目前,我有以下MSBuild命令:
msbuild / t:Build / p:Configuration = Release / p:OutputPath = C:\MySolutionOutput\ MySolution.sln然而,编译我的解决方案中有多个项目。当我用解决方案文件进行构建时,它将所有项目输出复制到同一个目录,Project2的输出将覆盖Project1的输出(或其内置的任何顺序)。
相反,我希望MSBuild将每个项目放在项目名称的子文件夹中。
msbuild / t:Build / p:Configuration = Release / p:OutputPath = C:\MySolutionOutput\ $(ProjectName) MySolution.sln但是, $(ProjectName)语法不起作用文字名为$(ProjectName)。
如何使MSBuild解决方案将每个项目的输出输出到OutputPath的子目录,最好不要制作MSBuild xml文件,或单独建立每个项目?
为了进一步说明,我的项目如下。
+项目1 + File1.txt + File2.txt + ReadMe.txt +项目2 + File3.txt + File4.txt + ReadMe.txt / pre>我的构建输出
C:\MySolutionOutput \File1.txt C:\MySolutionOutput\File2.txt C:\MySolutionOutput\File3.txt C:\MySolutionOutput\File4.txt C:\MySolutionOutput\ReadMe.txt ^ - (这是第二个自述文件,项目1的readme被覆盖)我想要什么
C:\MySolutionOutput\Project 1\File1。 txt C:\MySolutionOutput\Project 1\File2.txt C:\MySolutionOutput\Project 1\ReadMe.txt C:\MySolutionOutput \Project 2\File3.txt C:\MySolutionOutput\Project 2\File4.txt C:\MySolutionOutput\Project 2\ReadMe.txt解决方案
使用msbuild的解决方案,它将内部将解决方案转换为构建所有项目的msbuild xml文件,并将属性(如OutputPath)传递给它,并且没有办法干扰此行为。一个可能的解决方案需要你自己编写msbuild文件,但修改很小。你没有提到你正在使用的项目类型,但原则是相同的任何类型,这里是C#项目的一个示例:
- 创建一个通用的文件,允许按照你想要的方式覆盖OutputPath,但除非特别说明,否则不需要保留现有行为,否则不需要
- 在每个项目中导入该文件
- 在命令行上指定自定义输出目录
msbuild文件,说 outputpath.props :
<?xml version =1.0encoding =utf- 8\" >?; < Project ToolsVersion =12.0xmlns =schemas.microsoft/developer/msbuild/2003> < PropertyGroup> < OutputPath Condition ='$(OutputPathBaseDir)'!=''> $(OutputPathBaseDir)\ $(MSBuildProjectName)\< / OutputPath> < / PropertyGroup> < / Project>每个项目中的这里我使用相对路径,但可以引用$(SolutionDir)等;对于c#项目,请在显示之前插入此行
< Import Project =.. \outputpath.props /> <! - 以下是每个c#项目中的现有行 - > < Import Project =$(MSBuildToolsPath)\Microsoft.CSharp.targets/>现在构建:
msbuild mysolution.sln / p:OutputPathBaseDir = C:\MySolutionOutput
Currently, I have the following MSBuild command:
msbuild /t:Build /p:Configuration=Release /p:OutputPath=C:\MySolutionOutput\ MySolution.slnWhich compiles, however, I have multiple projects in my solution. When I do a build this way with the solution file, it copies all project outputs to the same directory, and the output from Project2 overwrites the output from Project1 (or whatever order they're built in).
Instead, I want MSBuild to put each project into a subfolder of the project name.
msbuild /t:Build /p:Configuration=Release /p:OutputPath=C:\MySolutionOutput\$(ProjectName) MySolution.slnHowever, the $(ProjectName) syntax does not work as it literally makes a folder called $(ProjectName).
How do I make MSBuild solution building output each project to a subdirectory of the OutputPath, preferably without making MSBuild xml files, or building each project individually?
To illustrate further, my projects are as follows.
+ Project 1 + File1.txt + File2.txt + ReadMe.txt + Project 2 + File3.txt + File4.txt + ReadMe.txtWhat my build outputs
C:\MySolutionOutput\File1.txt C:\MySolutionOutput\File2.txt C:\MySolutionOutput\File3.txt C:\MySolutionOutput\File4.txt C:\MySolutionOutput\ReadMe.txt ^-- (this is the 2nd readme, project 1's readme gets overwritten)What I want
C:\MySolutionOutput\Project 1\File1.txt C:\MySolutionOutput\Project 1\File2.txt C:\MySolutionOutput\Project 1\ReadMe.txt C:\MySolutionOutput\Project 2\File3.txt C:\MySolutionOutput\Project 2\File4.txt C:\MySolutionOutput\Project 2\ReadMe.txt解决方案
When building a solution using msbuild, it internally transforms the solution into an msbuild xml file which builds all projects and passes properties like OutputPath to it, and afaik there isn't a way to interfere with how this behaves. One possible solution does require you to write msbuild files yourself, but the modifications are really minor. You don't mention which project type you're using but the principle is the same for any type, and here's a sample for C# projects:
- create a common file which allows overriding OutputPath in the way you want it, but does nothing unless specifically told to in order to keep existing behaviour if needed
- import that file in each project
- specify custom output directory on the command line
msbuild file, say outputpath.props:
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" xmlns="schemas.microsoft/developer/msbuild/2003"> <PropertyGroup> <OutputPath Condition="'$(OutputPathBaseDir)' != ''">$(OutputPathBaseDir)\$(MSBuildProjectName)\</OutputPath> </PropertyGroup> </Project>import in each project; here I am using a relative path but you could reference eg $(SolutionDir) etc; for c# projects, insert this line right before the one shown
<Import Project="..\outputpath.props" /> <!--the below is an existing line in every c# project--> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />now build:
msbuild mysolution.sln /p:OutputPathBaseDir=C:\MySolutionOutput
更多推荐
MSBuild解决方案命令行输出到单个文件夹
发布评论