Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the output path of several visual C# projects

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.
like image 646
Paul Dixon Avatar asked Mar 07 '09 07:03

Paul Dixon


People also ask

How do I change the output path in Visual Studio?

Right-click on the project node in Solution Explorer and select Properties. Expand the Build section, and select the Output subsection. Find the Base output path for C#, and type in the path to generate output to (absolute or relative to the root project directory), or choose Browse to browse to that folder instead.

How do I change the build path in Vscode?

You may add -o arg with the desired path. For example, change to: ... "command": "dotnet build -o ${workspaceRoot}/bin/another_Debug/", ...

What is output directory?

output directory. [ESRI software] In ArcIMS, the folder designated during installation to hold files being served to users for display in a browser.


1 Answers

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"> <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:

<Import Project="..\Common.proj" /> 

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 it 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.

like image 188
Bas Bossink Avatar answered Sep 23 '22 22:09

Bas Bossink