I have a .Net Core application that has been published as a single file executable. When I run any of the following code from within Visual Studio, I get the expected result:
Assembly.GetAssembly(typeof(Installer)).GetName().Version.ToString();
Assembly.GetEntryAssembly().GetName().Version.ToString();
Assembly.GetExecutingAssembly().GetName().Version.ToString();
But when the above code is run within the published application (in production) it always returns "0.0.0.0"
Have you tried this? I created a new project and it seemed to work.
Assuming you're using Visual Studio 2019.
Right-click project -> Edit Project File -> Add GenerateAssemblyInfo element like below:
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> </PropertyGroup> </Project>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.