如何使用MSBuild更改AssemblyProduct,AssemblyTitle?

编程入门 行业动态 更新时间:2024-10-12 01:31:38
本文介绍了如何使用MSBuild更改AssemblyProduct,AssemblyTitle?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个MSBuild脚本,可以编译我现有的解决方案,但是我想在编译时更改解决方案中的一个项目 的某些属性,包括但不限于AssemblyProduct和AssemblyTitle

I have an MSBuild script which compiles my existing solution but I'd like to change some properties of one of the projects within the solution at compile-time, including but not limited to AssemblyProduct and AssemblyTitle.

这是我的构建脚本的片段:

Here's a snippet of my build script:

<Target Name="Compile" > <MSBuild Projects="..\MySolution.sln" Properties="Configuration=MyReleaseConfig;Platform=x86" /> </Target>

我有一个主要的可执行文件和几个已编译的DLL.我知道 MSBuild扩展包,我怀疑它可能会帮助我到达需要的位置,尽管我不确定该如何进行.

I've got one main executable and several DLLs that are compiled. I am aware of the MSBuild Extension Pack and I suspect it might help me to get to where I need to be, although I'm not sure how to proceed.

我可以在构建时有选择地更改AssemblyInfo属性吗?

Can I selectively change AssemblyInfo properties at build time?

推荐答案

使用MSBuild扩展包,您的位置正确.

You're on the right track with the MSBuild Extension Pack.

我发现在构建时有条件地生成程序集详细信息的最简单方法是将"AssemblyVersion"目标直接添加到需要更新的AssemblyInfo文件的.csproj文件中.您可以将目标直接添加到需要更新的AssemblyInfo文件的每个csproj文件中,或者按照我的意愿,使用AssemblyVersion目标创建一个自定义目标文件,并使每个csproj文件都包含您的自定义目标文件.

I find the easiest way to conditionally generate the assembly details at build time is to add an "AssemblyVersion" target directly to my .csproj file(s) that require an updated AssemblyInfo file. You can add the target directly to each csproj file that requires an updated AssemblyInfo file, or as I prefer to do it, create a custom targets file with the AssemblyVersion target and have each csproj file include your custom targets file.

您可能想使用MSBuild扩展包或 MSBuild社区任务来使用它们的任何一种方式各自的AssemblyInfo任务.

Either way you likely want to use the MSBuild Extension Pack or the MSBuild Community Tasks to use their respective AssemblyInfo task.

以下是我们构建脚本中的一些代码:

Here's some code from our build scripts:

<!-- Import the AssemblyInfo task --> <Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets"/> <!-- Overriding the Microsoft.CSharp.targets target dependency chain --> <!-- Call our custom AssemblyVersion target before build, even from VS --> <PropertyGroup> <BuildDependsOn> AssemblyVersion; $(BuildDependsOn) </BuildDependsOn> </PropertyGroup> <ItemGroup> <AssemblyVersionFiles Include="$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs"/> </ItemGroup> <Target Name="AssemblyVersion" Inputs="@(AssemblyVersionFiles)" Outputs="UpdatedAssemblyVersionFiles"> <Attrib Files="%(AssemblyVersionFiles.FullPath)" Normal="true"/> <AssemblyInfo CodeLanguage="CS" OutputFile="%(AssemblyVersionFiles.FullPath)" AssemblyCompany="$(CompanyName)" AssemblyCopyright="Copyright $(CompanyName), All rights reserved." AssemblyVersion="$(Version)" AssemblyFileVersion="$(Version)"> <Output TaskParameter="OutputFile" ItemName="UpdatedAssemblyVersionFiles"/> </AssemblyInfo> </Target>

更多推荐

如何使用MSBuild更改AssemblyProduct,AssemblyTitle?

本文发布于:2023-11-13 11:05:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584189.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   MSBuild   AssemblyTitle   AssemblyProduct

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!