如何设置的几个Visual C#项目的输出路径 [英] How to set the output path of several visual C# projects

查看:1901
本文介绍了如何设置的几个Visual C#项目的输出路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含几个C#项目的解决方案,我希望能够在一个地方一起设置所有项目的输出路径和其他属性。属性表(vsprops)似乎并没有能够提供C#项目和$(SolutionDir)变量被忽略。是否有任何其他的方法来跨越几个C#项目设置属性?

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?

更新
通过遵循由Bas Bossink答案的信息我能够通过创建一个共同的csproj并将其导入单个项目设置多个项目的输出路径。其他一些要点:

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:


  • 建筑在Visual Studio时,如果更改了共同的项目,必须触及发/装任何项目,这些项目引用它的被拾起的变化。

  • 这也在一个单个项目设置的任何属性将覆盖通用属性。

  • 设置$ (SolutionDir)作为通过Visual Studio的用户界面输出路径,因为该值作为一个字符串,而不是得到扩大治疗不能正常工作。但是,按预期工作设置$(SolutionDir)直接与文本编辑器的csproj文件。

推荐答案

一个的csproj文件已经是一个MSBuild文件,这意味着文件的csproj也可以使用导入元素所描述的这里。进口元素是
你需要什么。你可以创建一个包含像一个Common.proj:

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>

您可以在每个csprojs的导入这个Common.proj,比如像这样:

You can import this Common.proj in each of your csprojs, for instance like so:

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



import语句应先于依赖于Common.proj定义的属性的任何任务。

The import statement should precede any tasks that depend on the properties defined in Common.proj

我希望这有助于。我不能确认我已经用了很多次了$(SolutionDir)可变你的问题。然而,我知道,当你通过对包含在溶液中的特定项目的命令行中运行一个MSBuild命令,这个变量不被设置。它会被设置,当你建立在Visual Studio解决方案。

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.

这篇关于如何设置的几个Visual C#项目的输出路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆