I want to be able to display the current version of a .NET application that I have deployed using the publish wizard. There is a nice option to automatically update the version number every time I publish my application.
I found another question (Automatically update version number) that had this to get the current version:
Assembly.GetExecutingAssembly().GetName().Version
This gets you the version you set in the project properties, but not the version that is automatically incremented each time you publish.
Published your ASP.NET Core Web API as FDD So open Visual Studio and Go to File -> New -> Project. Select ASP.NET Core Web Application and click on Next. Give the proper name to your project and click on Create.
Build compiles the source code into a (hopefully) runnable application. Publish takes the results of the build, along with any needed third-party libraries and puts it somewhere for other people to run it.
You can use the following test
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed) { return System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion; }
to avoid the exception (as detailed in this post).
Also, I don't think you can get the current publish version via Visual Studio debugging because accessing CurrentDeployment
will throw an InvalidDeploymentException
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With