How do I override CopyLocal (Private) setting for references in .NET from MSBUILD

后端 未结 3 824
清酒与你
清酒与你 2020-11-28 08:27

I have been wrestling with this for a few days and after tons of searching I can\'t find the path I should be on.

What I want to do is set up an MSBUILD project that

3条回答
  •  囚心锁ツ
    2020-11-28 08:43

    In a file like filter.targets add a target:

    
      
            
               False
            
            
            
      
    
    

    This will recreate the @(Reference) list to have the metadata 'Private' set to false, which will ensure that the reference doesn't get copied. Then run build your solution or project with the property $(CustomAfterMicrosoftCommonTargets) set to the path to this filter.targets file.

    msbuild foo.sln /p:CustomAfterMicrosoftCommonTargets=c:\foo\filter.targets
    

    This way, the BeforeBuild target will get invoked before building the project, and all references will be set accordingly. If you want more control over when or whether Private should be false or true, you can alter the BeforeBuild target and control that via properties.

    Edit: There might be a better way to set the metadata in the BeforeBuild target.

提交回复
热议问题