代码之家  ›  专栏  ›  技术社区  ›  Kaizer69

VisualStudio使用的生成目标通过msbuild命令行进行增量生成

  •  0
  • Kaizer69  · 技术社区  · 5 年前

    我在我们的C项目中创建了一个任务,当项目在发布模式下构建(进行更改)时,可以自动版本化项目。版本控制部分工作得很好。但是,所有的项目都在构建中,不管项目是否在从命令行完成时发生了更改。这会导致不必要地对项目进行版本控制。在visualstudioworks中构建时,不会生成未更改的项目,但是我们使用msbuild.exe文件当我们在竹子上工作的时候,我们把这个作为一个临时的解决方案,而且这种方法总是盲目的构建,即使项目没有任何变化。我需要能够确定是否对项目进行了更改。

    有点像

    “$(wasSourceUpdated)”==“true”或要在我的自定义版本控制目标上使用的某种目标条件。

    <Import Project="..\..\DXT.BuildTasks\Targets\DXTAutoIncrementVersion.targets" Condition="Exists('..\..\DXT.BuildTasks\Targets\DXTAutoIncrementVersion.targets') And '$(Configuration)|$(Platform)' == 'Release|AnyCPU' And '$(DeployOnBuild)' != 'true'" />
    

    我也查过了 this this

    编辑

    我需要在实际执行构建之前运行该任务,以便用新版本标记生成的程序集

    编辑2

    我真正想要的是 或者逃跑 当我检测到程序集被更新时

    我目前所做的努力:

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

    提前谢谢

    0 回复  |  直到 4 年前
        1
  •  1
  •   Kaizer69    5 年前

    所以感谢Lance让我了解了MSBuild,让我更好地理解了这个问题。

    在对默认任务进行了很长时间的研究之后,我发现 this

    输入和输出与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>
    
        2
  •  0
  •   LoLance    5 年前

    Normal,我们可以将下面的脚本添加到.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>
    

    在生成期间,当项目真正发生更改时,将调用它。看到这个了吗 similar issue

    至于你的情况:

    你的任务和目标似乎来自目标文件 DXTAutoIncrementVersion.targets

    请检查 tasks targets .targets 文件。

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

    2.目标将任务分组。

    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