Import .targets file from command line in msbuild

后端 未结 4 2156
野性不改
野性不改 2021-02-15 02:23

I currently have multiple projects being build using msbuild. I have a small customisation to the build that is handled by a .targets file. One solution is to add the snippet

4条回答
  •  不知归路
    2021-02-15 03:22

    You can do that easily with MSBuild 4.0 (check your version by top-level attribute ToolsVersion="4.0"):

    There are multiple properties you can use to import your targets before and after Common.targets and or CSharp.targets loaded.

    Simplest way is to use 2 sets of self explaining properties. First set is: $(CustomBeforeMicrosoftCommonTargets) $(CustomAfterMicrosoftCommonTargets)

    and second one:

    $(CustomBeforeMicrosoftCSharpTargets)
    $(CustomAfterMicrosoftCSharpTargets)
    

    Property names are pretty self-explained.

    Just pass full file name to any of this properties via msbuild.exe e.g.

    msbuild.exe /p:CustomBeforeMicrosoftCSharpTargets=c:\mytargets\custom.targets
    

    You can use other "ImportByWildcard(Before|After)...." properties if you need to import multiple files. But in that case you need to pass more parameters to command-line.

提交回复
热议问题