獲取.Net Core 3.1 單文件可執行版本號 (Get .Net Core 3.1 single-file executable version number)


問題描述

獲取.Net Core 3.1 單文件可執行版本號 (Get .Net Core 3.1 single‑file executable version number)

我有一個已發佈為單個文件可執行文件的 .Net Core 應用程序。當我在 Visual Studio 中運行以下任何代碼時,我會得到預期的結果:

Assembly.GetAssembly(typeof(Installer)).GetName().Version.ToString();
Assembly.GetEntryAssembly().GetName().Version.ToString();
Assembly.GetExecutingAssembly().GetName().Version.ToString();

但是當上述代碼在已發布的應用程序(生產中)中運行時,它總是返回“0.0.0.0”


參考解法

方法 1:

Have you tried this? I created a new project and it seemed to work.

Assuming you're using Visual Studio 2019.

  1. Right‑click project ‑> Add ‑> New Item ‑> Assembly Information File
  2. You will then have a AssemblyInfo.cs file with the assembly version in
  3. You then need to ignore the generated assembly version so you need to add GenerateAssemblyInfo with false to your .csproj.
  4. 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>
    

方法 2:

The assembly version should be set in the properties of the project which you're compiling.

Right‑click project ‑> Properties ‑> Package:

enter image description here

(by MatthewShoejepDSN)

參考文件

  1. Get .Net Core 3.1 single‑file executable version number (CC BY‑SA 2.5/3.0/4.0)

#Version #asp.net-core #C#






相關問題

XCode4 Organizer - 由於 CFBundleVersion 錯誤,應用程序驗證失敗 (XCode4 Organizer - App fails validation due to CFBundleVersion error)

如何避免編譯iOS 4.0提供的常量,並內置到iOS 3.1的設備中 (How to avoid compiling the constant which is provided in iOS 4.0, and build into the device with iOS 3.1)

如何從 CLI 中查找 php 中內置模塊的版本號 (how to find the version numbers of built in modules in php from the CLI)

Tài liệu trực tuyến Ruby / GSL cho phiên bản sai? (Ruby/GSL online documentation for wrong version?)

如何配置我的 SBT 以使用帶有指定插件的插件? (How to configure my SBT to use a plugin with a specified plugin?)

安裝舊版本的 Python 以在 Mac OS X 上進行測試 (Install older versions of Python for testing on Mac OS X)

檢測/指紋手機品牌和型號的替代方法? (Alternative way to detect/fingerprint phone make and model?)

實體框架發布揭秘 (Entity Framework Releases Demystified)

android SDK 版本之間的差異 (Difference between android SDK versions)

如何檢索顯示上游狀態的 git 版本信息 (How do I retrieve git version info showing upstream state)

嘗試使用 get-PnPFile 從 OneDrive 獲取文件的所有版本時找不到文件 (File not found trying to get all versions of a file from OneDrive using get-PnPFile)

獲取.Net Core 3.1 單文件可執行版本號 (Get .Net Core 3.1 single-file executable version number)







留言討論