views:

2279

answers:

4

I have a solution that contains several c# projects and I would like to be able to set the output path and other properties on all the projects together in a single place. Property Sheets (vsprops) do not seem to be able available for C# projects and the $(SolutionDir) variable is ignored. Are there any other methods to set properties across several C# projects?

Update By Following the information in the answer by Bas Bossink I was able to set the output path of several projects by creating a common csproj and importing it into the individual project. A few other points:

  • When building in Visual Studio if changes are made to the common project it is necessary to touch/reload any projects that reference it for the changes to be picked up.
  • Any properties which are also set in a individual project will override the common properties.
  • Setting $(SolutionDir) as the output path via the Visual Studio UI does not work as expected because the value is treated as a string literal rather than getting expanded. However, Setting $(SolutionDir) directly into the csproj file with a text editor works as expected.
A: 

I would suggest you to use a build tool such as MSBuild or NAnt which would give you more flexibility on your builds. Basically the idea is to kick off a build using (in most cases) a single configurable build file.

I would personally recommend NAnt.

You could find an awesome tutorial on NAnt on JP Boodhoo's blog here

AB Kolan
A: 

Unfortunately, these bits of information such as output path are all stored inside the individual *.csproj files. If you want to batch-update a whole bunch of those, you'll have to revert to some kind of a text-updating tool or create a script to touch each of those files.

For things like this (apply changes to a bunch of text files at once) I personally use WildEdit by Helios Software - works like a charm and it's reasonably priced.

But I'm sure there are tons of free alternatives out there, too.

Cheers, Marc

marc_s
+4  A: 

A csproj file is already an msbuild file, this means that csproj files can also use an import element as described here. The import element is exactly what you require. You could create a Common.proj that contains something like:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
<PropertyGroup>
 <OutputPath>$(SolutionDir)output</OutputPath>
 <WarningLevel>4</WarningLevel>
 <UseVSHostingProcess>false</UseVSHostingProcess>
 <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>

You can import this Common.proj in each of your csprojs, for instance like so: The import statement should precede any tasks that depend on the properties defined in Common.proj

I Hope this helps. I can't confirm your problems with the $(SolutionDir) variable I've used many times. I do know however that this variable does not get set when you run an msbuild command via the commandline on a specific project that is contained in a solution. It will be set when you build your solution in Visual Studio.

Bas Bossink
A: 

hi,

I have a follow-up qn on this. Can I use multiple output paths. like when i build my project, the exe should generate in two different paths. is this possible? if so, how to configure the project properties?

satya
Better ask a follow-up question like this as a new question, not post it here as an answer. More people would see it and try to solve the problem, and it isn't really an answer to this question :).
sth