繁体   English   中英

Visual Studio用于通过msbuild命令行进行增量生成的生成目标

[英]Build target used by Visual Studio to do Incremental Build via msbuild command line

我在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>

提前致谢

因此,感谢Lance使我理解MSBuild,以至于我更好地理解了问题。

经过漫长的时间来研究默认任务,我跑在这个疑问,有完美的解决了我的问题。 应用此修复程序后,版本控制任务现在仅在对msbuild代码进行更改时才运行。

输入和输出与CoreCompile目标相同,并确保仅在源发生更改时才运行任务

这是我运行的有效目标:

<?xml version="1.0" encoding="utf-8"?>
<Project>
    <PropertyGroup>
        <CoreCompileDependsOn>
        $(CoreCompileDependsOn);
        IncrementVersionBeforeBuild
        </CoreCompileDependsOn>
    </PropertyGroup>
    <Target Name="IncrementVersionBeforeBuild"
            Inputs="$(MSBuildAllProjects);
            @(Compile);                               
            @(_CoreCompileResourceInputs);
            $(ApplicationIcon);
            $(AssemblyOriginatorKeyFile);
            @(ReferencePath);
            @(CompiledLicenseFile);
            @(EmbeddedDocumentation); 
            $(Win32Resource);
            $(Win32Manifest);
            @(CustomAdditionalCompileInputs)"
            Outputs="@(DocFileItem);
             @(IntermediateAssembly);
             @(_DebugSymbolsIntermediatePath);                 
             $(NonExistentFile);
             @(CustomAdditionalCompileOutputs)"
    >
        <Message Text="Version Task running" 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>
    <UsingTask AssemblyFile="$(TaskPath)\AutoVersionTask.dll" TaskName="AutoVersionTask.IncrementVersion" />

    <PropertyGroup>
        <_ProjectVersioned>true</_ProjectVersioned>
    </PropertyGroup>
</Project>

通常,我们可以将以下脚本添加到.csproj文件中:

  <PropertyGroup>
    <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
  </PropertyGroup>
  <Target Name="AutoVersionWhenBuild" AfterTargets="CoreBuild"
          Condition="'$(_AssemblyTimestampBeforeCompile)'!='$(_AssemblyTimestampAfterCompile)'">
    <Message Importance="high" Text="Auto-version begins when changes are made!"/>
    <!--<AutoVersionTask>Do your auto-version task here.</AutoVersionTask>-->
  </Target>

当真正对项目进行更改时,将在构建过程中调用它。 看到这个类似的问题

至于你的情况:

看来您的任务和目标来自目标文件DXTAutoIncrementVersion.targets ,您可以打开该文件并将其中的目标更改为上面的格式。

另外:请检查任务目标.targets文件之间的关系。

1.MSBuild使用任务执行这些操作。

2.Targets将任务分组在一起。

3.MSBuild包含几个.targets文件,其中包含常见方案的项目,属性,目标和任务。

因此,您可以modify your auto-version target in the xx.targets file ,也可以use the script above, and call the auto-version task in the AutoVersionWhenBuild target 希望能帮助到你:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM