Can you prevent MSBuild.exe from running Build Events?

后端 未结 9 1785
我在风中等你
我在风中等你 2020-12-08 00:11

I\'m building a number of projects via a script, and the occasional use of custom build events causes a great deal of difficulty for the build system. If it is possible, I\

相关标签:
9条回答
  • 2020-12-08 00:48

    By default when you import Microsoft.Common.targets you get

    <PropertyGroup>
        <BuildDependsOn>
            BeforeBuild;
            CoreBuild;
            AfterBuild
        </BuildDependsOn>
    </PropertyGroup>
    

    I think you can maybe just replace it with

    <PropertyGroup>
        <BuildDependsOn>
            CoreBuild
        </BuildDependsOn>
    </PropertyGroup>
    

    to turn off these pre/post build events. (Not sure if you need to put that in your .proj file before or after the import, or if you need to modify Microsoft.Common.targets to have such an effect. Don't have time to experiment right now...)

    0 讨论(0)
  • 2020-12-08 00:53

    In some C# projects I need PostBuildEvent works in Visual studio build, but not works in MSBuild and TFS build. For this purpose I add PostBuildEvent in VS. It sets below code in .csproj:

      <PropertyGroup>
        <PostBuildEvent>*... my custom post build event ....*</PostBuildEvent>
      </PropertyGroup>
    

    after that I add below codes to .csproj:

      <Target Name="BeforeBuild">
          <PropertyGroup Condition="'$(BuildingInsideVisualStudio)' == 'false' Or '$(BuildingInsideVisualStudio)' != 'true'">
            <PostBuildEvent></PostBuildEvent>
          </PropertyGroup>
      </Target>
    

    This code sets PostBuildEvent to empty and it occurs only in MSBuild and TFSBuild BeforeBuild target. It is simple, permanent, not need to set params and works fine.

    0 讨论(0)
  • 2020-12-08 00:54

    You could also make the property conditional

    <PreBuildEvent Condition="'$(BuildingInsideVisualStudio)' == '' Or '$(BuildingInsideVisualStudio)' == true"> ... </PreBuildEvent>
    
    0 讨论(0)
提交回复
热议问题