简体   繁体   中英

MSBuild + Visual studio: Customize default “Copy Local” for all projects in the solution

I know very little about MSBuild.

Recently I read that setting 'copy local' to false for large solution can significantly decrease compilation time. I found a way to set the default setting to be false by setting a machine wide file called CustomAfterMicrosoftCommon.targets in the MSBuild extension path.

This worked well, however, there are a few problems with that approach.

-This default value setting is system wide and I would like to it to be only for a specific solution. I don't it at the project level because I have lots of them in several different solutions.

-I want this default value to be applied on to "Non Output projects". By this I mean that class library projects should not have copy local set to true. However, the main application project needs copy local to true for class libraries dependencies since it needs to run. Ideally, for those output projects, I'd like to fallback to the more intelligent out of the box default value that is smart enough to determine whether a reference should be private or not. I guess I could have the default be Copy Local false, and then explicitely set Copy Local to true wherever it is necessary. That's not too bad given that you typically don't have many output projects but I'd like to see if some people have come up with better solution.

Any ideas?

Msbuild finds the target extensions like this %MSBuildExtensionsPath%\v4.0\CustomAfterMicrosoftCommon.targets

So one way to solve your first problem is to somehow only set MSBuildExtensionsPath for the solution where you want to apply your own defaults.

I solved the second problem in another way. I kept copylocal=false also on the "main application project". Instead I added the other project's output path to the DEVPATH environment variable.

SET DEVPATH=C:\Proj1\Output;C:\Proj2\Output

(and doing the necessary changes to machine.config as specified here )

Edit:

Here is nice page about how to make settings with project or solution scope

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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