This tutorial shows how to publish a console app so that other users can run it. Publishing creates the set of files that are needed to run your application. To deploy the files, copy them to the target machine.
Start Visual Studio 2019. On the start page, choose Create a new project. On the Create a new project page, enter console in the search box. Next, choose C# or Visual Basic from the language list, and then choose All platforms from the platform list. This video is for Seneca students to follow for installing Visual Studio 2017 and Creating Simple C and C console apps.Download Visual Studio:https://www.v.
- Open Visual Studio. On the start window, choose Create a new project. In the Create a new project window, choose C# from the Language list. Next, choose Windows from the Platform list and Console from the project types list.
- Automated testing is very expensive, but when it goes around console applications, there is a way to avoid spending much time and effort on implementing automation. Welcome to the world of console testing. Solution, project and assembly are used in Visual Studio/.NET meaning.
- When doing a console application in Java with Eclipse, I see the output being put in a text box in the IDE itself, instead of having a console popping up like in Visual Studio. This comes in handy, as even after the program has exited, I can still make good use of the text that was written in it, as it doesn't get erased until I run it again.
Prerequisites
- This tutorial works with the console app that you create in Create a .NET console application using Visual Studio.
Publish the app
Start Visual Studio.
Open the HelloWorld project that you created in Create a .NET console application using Visual Studio.
Make sure that Visual Studio is using the Release build configuration. If necessary, change the build configuration setting on the toolbar from Debug to Release.
Right-click on the HelloWorld project (not the HelloWorld solution) and select Publish from the menu.
On the Target tab of the Publish page, select Folder, and then select Next.
On the Specific Target tab of the Publish page, select Folder, and then select Next.
On the Location tab of the Publish page, select Finish.
On the Publish tab of the Publish window, select Publish.
Inspect the files
By default, the publishing process creates a framework-dependent deployment, which is a type of deployment where the published application runs on machine that has the .NET runtime installed. Users can run the published app by double-clicking the executable or issuing the dotnet HelloWorld.dll
command from a command prompt.
In the following steps, you'll look at the files created by the publish process.
In Solution Explorer, select Show all files.
In the project folder, expand bin/Release/net5.0/publish.
As the image shows, the published output includes the following files:
HelloWorld.deps.json
This is the application's runtime dependencies file. It defines the .NET components and the libraries (including the dynamic link library that contains your application) needed to run the app. For more information, see Runtime configuration files.
HelloWorld.dll
This is the framework-dependent deployment version of the application. To execute this dynamic link library, enter
dotnet HelloWorld.dll
at a command prompt. This method of running the app works on any platform that has the .NET runtime installed.HelloWorld.exe
This is the framework-dependent executable version of the application. To run it, enter
HelloWorld.exe
at a command prompt. The file is operating-system-specific.HelloWorld.pdb (optional for deployment)
This is the debug symbols file. You aren't required to deploy this file along with your application, although you should save it in the event that you need to debug the published version of your application.
HelloWorld.runtimeconfig.json
This is the application's run-time configuration file. It identifies the version of .NET that your application was built to run on. You can also add configuration options to it. For more information, see .NET run-time configuration settings.
Run the published app
In Solution Explorer, right-click the publish folder, and select Copy Full Path.
Open a command prompt and navigate to the publish folder. To do that, enter
cd
and then paste the full path. For example:Run the app by using the executable:
Enter
HelloWorld.exe
and press Enter.Enter a name in response to the prompt, and press any key to exit.
Run the app by using the
dotnet
command:Enter
dotnet HelloWorld.dll
and press Enter.Enter a name in response to the prompt, and press any key to exit.
Additional resources
Visual Studio Console Application Exe
Next steps
Visual Studio Console Application Args
In this tutorial, you published a console app. In the next tutorial, you create a class library.