我正在.NET 6 中开发一个WPF 应用程序。该应用程序将使用ClickOnce 发布,我的目标是显示应用程序中的版本号。我看到了 System.Deployment,但不幸的是这似乎仅适用于 .NET Framework 应用程序。我对这个问题的第一个想法是使用标准的 Publish.html 文件并从中读取版本。然而,这个解决方案感觉有点奇怪,并且只能部分工作,因为它显示的是最新版本,而不是用户实际安装的版本。
对于这个问题还有其他方法吗?
I am developing a WPF application in .NET 6. The application will be published using ClickOnce and my goal is to display the number of the version in the application. I saw System.Deployment, but unfortunately this seems to be available only for .NET Framework applications. My first thought on this problem was to use the standard Publish.html file and read the version from it. However, this solution feels a little bit weird and does only work partially, as it displays the most current version and not the version the user has actually installed.
Are there any other approaches for this issue?
发布评论
评论(2)
我遇到了同样的问题,就我而言,发布的版本实际上是我想要显示的唯一版本。我的解决方案是通过将以下目标添加到我的 .csproj 文件中,用已发布的版本覆盖程序集版本:
执行此操作后,
Assembly.GetExecutingAssembly().GetName().Version
中给出的版本您发布的应用程序将与您发布的版本相同。请注意,这会覆盖实际的程序集版本,如果您在未发布的情况下进行构建,则会添加类似 1.0.0.0 的内容。就我的目的而言,这并不重要,但我确信您可以添加某种条件来阻止该目标在发布版本之外运行。
I was having the same issue, and in my case the published version was really the only version I cared to display. My solution was to overwrite the assembly version with the published version by adding the following target to my .csproj file:
After doing this, the version given by
Assembly.GetExecutingAssembly().GetName().Version
in your published application will be the same as your published version.Note that this overwrites the actual assembly version, and will put something like 1.0.0.0 if you build without publishing. For my purposes this didn't matter, but I'm sure you can add some sort of condition which prevents this target from running outside of publish builds.
自.NET 7以来,我们可以获得ClickOnce的版本。
我成功了。
Since .NET 7, we can get ClickOnce's version.
I succeeded it.
https://learn.microsoft.com/en-us/visualstudio/deployment/access-clickonce-deployment-properties-dotnet?view=vs-2022