[英]MSBuild ZipDirectory Output Different when Building Solution and Building Individual Project
[英]MSBuild solution command line output to individual folders
目前,我有以下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文件,或单独构建每个项目?
为了进一步说明,我的项目如下。
+ Project 1
+ File1.txt
+ File2.txt
+ ReadMe.txt
+ Project 2
+ File3.txt
+ File4.txt
+ ReadMe.txt
我的构建输出了什么
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)
我想要的是
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等属性传递给它,并且afaik无法干扰其行为方式。 一种可能的解决方案确实需要您自己编写msbuild文件,但修改确实很小。 您没有提到您正在使用的项目类型,但任何类型的原则都是相同的,这里是C#项目的示例:
msbuild文件,比如outputpath.props
:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputPath Condition="'$(OutputPathBaseDir)' != ''">$(OutputPathBaseDir)\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
</Project>
进口每个项目; 这里我使用的是相对路径,但你可以参考例如$(SolutionDir)等; 对于c#项目,请在显示的那一行之前插入此行
<Import Project="..\outputpath.props" />
<!--the below is an existing line in every c# project-->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
现在建立:
msbuild mysolution.sln /p:OutputPathBaseDir=C:\MySolutionOutput
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.