我正在尝试更新AssemblyInfo.cs文件以反映项目的下一个发布版本,在进行任何其他构建步骤之前。
在我的项目文件中,我在结尾之前添加了以下内容:
<Import Project="$(ProjectDir)Properties\PublishVersion.proj" />
PublishVersion.proj的内容如下:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<Target Name="BeforeBuild">
<FormatVersion Version="$(ApplicationVersion)" Revision="$(ApplicationRevision)">
<Output TaskParameter="OutputVersion" PropertyName="SetVersion" />
</FormatVersion>
<FileUpdate Files="$(ProjectDir)Properties\AssemblyInfo.cs"
Regex="\d+\.\d+\.\d+\.\d+"
ReplacementText="$(SetVersion)" />
</Target>
</Project>
现在它确实会在构建完成之前的某个位置执行,但绝对不是在构建开始之前执行,因为当我查看生成的exe文件时,它具有在AssemblyInfo.cs中BUILD开始之前的文件版本,但.application文件和清单文件引用了新版本。
最终的清单文件(在构建开始之前为1.0.0.0,在构建后为1.0.0.4):
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly ...>
<asmv1:assemblyIdentity name="BHTechSupport.exe" version="1.0.0.4" ... />
...
<entryPoint>
<assemblyIdentity name="BHTechSupport" version="1.0.0.0" ... />
...
</entryPoint>
...
<dependency>
<dependentAssembly ... codebase="BHTechSupport.exe" ...>
<assemblyIdentity name="BHTechSupport" version="1.0.0.0" ... />
...
</dependentAssembly>
</dependency>
...
</asmv1:assembly>
我该如何确保我的目标在所有其他操作之前执行?
对于 PublishVersion.proj 的更改有时似乎不会生效,我需要清理解决方案并重新启动 Visual Studio 才能生效。
BeforeTargets
将无法工作,你必须使用DependsOnTargets
。 - sllDefaultTargets="MyTarget"
。 - sllDefaultTargets="MyTarget"
和InitialTargets="MyTarget"
在结果上没有区别。 - Lawrence Ward