Reputation: 101
I have a solution which contains a lot of C# projects, how can I change the configuration of all projects very quickly, like I want to change the output folder from bin to MyBin. I know C++ property sheet can do the similar thing but C# doesn't have property sheet.
Upvotes: 9
Views: 2191
Reputation: 20909
You can use a common 'partial' project file to store common stuff.
Move all the stuff that you want to be changed simultaneously into a stand-alone .proj file, e.g. common.proj
:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputPath>Debug</OutputPath>
<Platform>AnyCPU</Platform>
</PropertyGroup>
</Project>
Than use msbuild import declaration to 'include' common part into every project in your solution:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="common.proj" />
</Project>
MsBuild imports work more or less in the same manner as C++ includes: before a project is built all the import directives are replaced with the content of the imported file. Now you can change your common properties just in one file - common.proj
There's one important thing to mention: VS caches included project files, so you'd have to reload all the projects after applying a change to common.proj
file (so I suggest building from command-line when you actively change commom.proj
)
We use this approach to manage code-analysis settings (as they are supposed to be the same across all the projects in the solution).
Upvotes: 7
Reputation: 33506
You will now have many XMLs opened as text files.
Now use the Find&Replace (control-shift-H if you use default shortcuts), and set:
OutputPath>bin\Debug</OutputPath
MyBin\Debug
All open documents
and hit Replace All
.
Then do the same with bin\Release
and MyBin\Release
.
Then save all XMLs, then right-click on every project and choose "reload".
You can do the same in any text editor or any command-line find&replace utility like sed
. If you ave any, use them instead - it will save you from rightlicking/unloading all projects.
You can also exploit the fact that CSPROJs are just MSBuild files, so you can create a 'configuration' MSBuild script that will be included each of your C# projects, and which will define extra variables like 'common output path' etc. But while this certainly works (I've did it a few times), it will most probably screw up some PropertySheets in the VS UI in the most natural way, for example, if you use this to override/setup the OutputPaths, then the VS UI wil display empty or broken output paths and trying to use the VS UI to correct/change them will in turn overwrite your smart settings that read them from common config file. Obvious, isn't it.
EDIT: here it's quickly explained: Partial .csproj Files, however, please read my comments below too, just in case.
Upvotes: 1
Reputation: 62248
You have to define new Build Configuration
, which can be copied from Release or from Debug or constructed all manually. After you can customize for every project it's option in regard of that custom build you just created and you done. This is done, naturally, only once. After, whenever you choose that custom build all properties chosen for every single project in solution will be set with the properties you want.
Upvotes: 3