如何将版本附加到.NET标准2.0库项目中的汇编输出文件名
我正在使用VS2022 17.2.3。
在.NET标准2.0库项目中,我希望更改输出组件文件名。
在项目 - >属性 - >汇编名称,我看到它设置为 $(msbuildProjectName)
。
我想将其更改为 $(msbuildProjectName)$(assemblyversion)
,但是 $(assemblyversion)
不起作用。
我想问是否有人可以指向正确的事情。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是由于 msbuild的属性评估顺序。
设置
assemblyVersion
在csproj
file 之前,请先设置assemblyName
工作正常:在注释中,您还说您要想要使用通配符
汇编
,例如1.0。*
。我不知道访问MSBuild版本内部生成的扩展的最终形式的好方法,因此我只能提供稍微丑陋的后构建副本,从内置的组装中检索版本:
在后续评论中,您想要仅将主要版本附加到文件名。
您可以创建
system.version
汇编版本的实例,并调用其toString(int fieldCount)
方法,以便它仅返回前两个段。这将是新的帖子构建目标 - 我已经将结果存储在majorminor
属性sanity可读性中,但是如果您喜欢:我建议能够在几个月内向您的大学或您自己解释。也许有人知道这是一个不那么令人费解的解决方案。
This is due to MSBuild's Property Evaluation Order.
Setting
AssemblyVersion
in thecsproj
file before settingAssemblyName
works fine:In the comments, you also stated you want to use a wildcard
AssemblyVersion
, like1.0.*
.I don't know a good way to access the expanded, final form of the version MSBuild generates internally, so I can only offer a slightly ugly post build copy retrieving the version from the built assembly:
In a follow-up comment, you wanted to only append the major.minor version to the file name.
You can create a
System.Version
instance of the assembly version, and call itsToString(int fieldCount)
method so that it only returns the first 2 segments. This would be the new post build target - I've stored the result in aMajorMinor
property forsanityreadability, but you can bash it all into one line if you prefer:I suggest being able to explain this to your collegues or yourself in a few months. And maybe someone else knows a less convoluted solution for this.