[英]MSBuild copies dependencies when absolute path is specified and ignores when relative
I try to build .csproj
that references some projects in solution. 我尝试构建引用解决方案中某些项目的
.csproj
。 These references are marked with CopyLocal=False
. 这些引用标有
CopyLocal=False
。 And this is the desired behavior. 这是理想的行为。
I build it for CI using MSBuild, so I set output folder via /p:OutputPath="some output dir"
. 我使用MSBuild为CI构建它,所以我通过
/p:OutputPath="some output dir"
设置输出文件夹/p:OutputPath="some output dir"
。 I also set /p:SolutionDir="path to the solution"
to correctly resolve some NuGet references. 我还设置
/p:SolutionDir="path to the solution"
以正确解析一些NuGet引用。
The problem is: when I specify OutputPath with absolute path to the output directory (like d:\\solution\\build\\buildgroupsubfolder
), then MSBuild copies every dependency into output directory, I don't know why it is doing so. 问题是:当我指定OutputPath与输出目录的绝对路径(如
d:\\solution\\build\\buildgroupsubfolder
)时,MSBuild d:\\solution\\build\\buildgroupsubfolder
每个依赖项复制到输出目录中,我不知道为什么会这样做。 And if I specify output path with relative path (like ..\\..\\..\\..\\..\\build\\buildgroupsubfolder
) then MSBuild correctly handles CopyLocal=false
and doesn't copy references to output directory. 如果我指定具有相对路径的输出路径(如
..\\..\\..\\..\\..\\build\\buildgroupsubfolder
),则MSBuild正确处理CopyLocal=false
,并且不会将引用复制到输出目录。
We had some nesting in our solution, projects are divided into groups, so we want them to be build into sub folders. 我们在解决方案中有一些嵌套,项目分为几组,因此我们希望将它们构建到子文件夹中。 And I want to be able to specify build path relative to base build path and not to path of project itself.
我希望能够指定相对于基本构建路径的构建路径,而不是项目本身的路径。
Why does MSBuild ignore CopyLocal=false when absolute path is specified and treats it correctly when relative path is specified? 为什么MSBuild在指定绝对路径时忽略CopyLocal = false并在指定相对路径时正确处理它?
Well, I've digged further. 好吧,我进一步挖掘了。 I've found out that MSBuild misbehaves, but not where I've though about it.
我发现MSBuild行为不端,但我不知道它在哪里。
I've thought MSBuild had incorrect behavior as I described in my question. 我认为MSBuild的行为不正常,正如我在问题中描述的那样。 It really process
CopyLocal=false
as it should if I set OutputDir
to relative path. 如果我将
OutputDir
设置为相对路径,它确实会处理CopyLocal=false
。 And it misbehaves if I set OutputDir
to absolute path. 如果我将
OutputDir
设置为绝对路径,它会出错。 I found the answer in MSDN that says: 我在MSDN中找到了答案:
OutputPath - Specifies the path to the output directory, relative to the project directory , for example, "bin\\Debug".
OutputPath - 指定输出目录相对于项目目录的路径,例如“bin \\ Debug”。
So in fact MSBuild should warn me or even fail when I set OutputPath
to absolute path, but it doesn't. 所以事实上,当我将
OutputPath
设置为绝对路径时,MSBuild应该警告我甚至失败,但事实并非如此。 That's why I was under impression that absolute path is OK and there's a bug with CopyLocal
handling. 这就是为什么我的印象是绝对路径没问题,并且
CopyLocal
处理存在错误。 The actual bug is that MSBuild works when it should fail. 实际的错误是MSBuild在失败时工作。
I just had the same issue after switching my project and MSBuild from Visual Studio 2005 to Visual Studio 2010. However, I wanted to avoid having to use relative path, so instead I switched to using the new Web Publishing Pipeline (WPP) in .NET 4.0 by adding the following to my MSBuild command line: 我将项目和MSBuild从Visual Studio 2005切换到Visual Studio 2010后,我遇到了同样的问题。但是,我想避免使用相对路径,所以我转而使用.NET中的新Web发布管道(WPP)。 4.0将以下内容添加到我的MSBuild命令行:
/p:UseWPP_CopyWebApplication=True /p:PipelineDependsOnBuild=False
Now output is back to normal and still able to use absolute path in my output directory. 现在输出恢复正常,仍然可以在输出目录中使用绝对路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.