【发布时间】:2019-05-22 22:09:49
【问题描述】:
我在我们的 C# 项目中创建了一个任务,以便在项目在发布模式下构建(进行更改)时自动版本化项目。版本控制部分完美运行。但是,无论从命令行完成时项目是否实际更改,所有项目都在构建中。这会导致不必要地对项目进行版本控制。在 Visual Studio 中构建有效,未构建未更改的项目,但是我们制作了一个使用 msbuild.exe 进行自动构建的工具,并在我们使用 Bamboo 时将其用作临时修复,并且该方法总是进行盲构建,即使存在项目没有变化。我需要能够确定是否对项目进行了更改。
类似
'$(wasSourceUpdated)' == 'true' 或在我的自定义版本控制目标上使用的某种目标条件。
这是我在项目中的版本控制任务示例
<Import Project="..\..\DXT.BuildTasks\Targets\DXTAutoIncrementVersion.targets" Condition="Exists('..\..\DXT.BuildTasks\Targets\DXTAutoIncrementVersion.targets') And '$(Configuration)|$(Platform)' == 'Release|AnyCPU' And '$(DeployOnBuild)' != 'true'" />
编辑
我需要在实际执行构建之前运行该任务,以便用新版本标记生成的程序集
编辑 2
我真正想要的是在我检测到程序集已更新时运行 CoreCompile 或再次运行 CoreCompile 的条件
到目前为止我已经尝试过:
<Project>
<PropertyGroup>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<_AssemblyTimestampBeforeCompile>%(IntermediateAssembly.ModifiedTime)</_AssemblyTimestampBeforeCompile>
</PropertyGroup>
<PropertyGroup>
<_AssemblyTimestampAfterCompile>%(IntermediateAssembly.ModifiedTime)</_AssemblyTimestampAfterCompile>
</PropertyGroup>
<PropertyGroup>
<_ProjectVersioned Condition="'$(_ProjectVersioned)'==''">false</_ProjectVersioned>
</PropertyGroup>
<Target Name="IncrementVersionBeforeBuild" AfterTargets="CoreCompile" Condition="'$(_AssemblyTimestampBeforeCompile)'!='$(_AssemblyTimestampAfterCompile)' and '$(_ProjectVersioned)' == 'false'">
<Message Text="Before $(_AssemblyTimestampBeforeCompile) After $(_AssemblyTimestampAfterCompile)" Importance="High"/>
<IncrementVersion
ProjectPath="$(MSBuildProjectFullPath)"
VersionRule="3.3.0.+"
FileName="Properties\AssemblyInfo.cs">
</IncrementVersion>
</Target>
<PropertyGroup>
<TaskPath>$(MSBuildThisFileDirectory)..\Tasks\AutoVersionTask\AutoVersionTask\bin\Debug</TaskPath>
</PropertyGroup>
<!-- Sample import for projects
<Import Project="..\..\DXT.BuildTasks\Targets\DXTAutoIncrementVersion.targets" Condition="Exists('..\..\DXT.BuildTasks\Targets\DXTAutoIncrementVersion.targets') And '$(Configuration)|$(Platform)' == 'Release|AnyCPU' And '$(DeployOnBuild)' != 'true'" />
-->
<UsingTask AssemblyFile="$(TaskPath)\AutoVersionTask.dll" TaskName="AutoVersionTask.IncrementVersion" />
<PropertyGroup>
<_ProjectVersioned>true</_ProjectVersioned>
</PropertyGroup>
提前致谢
【问题讨论】:
-
您是否使用过构建后事件以及何时执行自动版本任务?在构建之后和发布之前?
-
自动版本任务在构建之前运行。发布被跳过,因为它可能导致自动版本任务在发布时运行两次
标签: c# visual-studio msbuild