MSBuild项目与解决方案的相对路径 [英] Relative paths with MSBuild project vs solution

查看:284
本文介绍了MSBuild项目与解决方案的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多项目都加入了解决方案.每个项目都有其自己的目录结构,并且csproj文件位于文件夹结构的不同级别. 每个csproj都有指定的OutputPath属性. OutputPath-是一个相对路径,它因项目而异,因此所有项目都具有相同的输出目录. 如果我构建一个单独的项目,就可以了.但是,如果我尝试构建解决方案文件,一切都会改变.在这种情况下,每个项目的输出文件夹都不同(取决于该项目的OutputPath中的".. \"数量).

I have a number of projects which are joined into a solution. Every project has it's own directory structure, and csproj files are located on diferrent level of folder structure. Every csproj has OutputPath property specified. OutputPath - is a relative path and it varies from project to project in such a way so all projects have the same output dir. It is work OK if I build a separate project. But everything changes if I try to build solution file. In this case every project output folder differs (depends on a number of '..\' in that project's OutputPath).

我确实知道,在片刻前一切正常.没有人更改build.cmd或任何sln或csproj文件.但现在我遇到了上述情况.

I do know, that before some moment all was working fine. Nobody changed build.cmd neither any sln or csproj files. But now I have situation described above.

所以我的问题是-什么会影响相对路径的评估方式?我的意思是我该如何强制从特定项目的csproj文件所在的文件夹开始评估相对的OutputPath.不是来自.sln文件所在的文件夹.

So my question is - what affects how relative path is evaluated? I mean how can I force relative OutputPath to be evaluated starting from folder where csproj file of that particular project is located. Not from folder where .sln file is.

Let's assume I have following directory structure:

dir1
  a.sln
  dir2
    a.csproj
  dir21
    dir3
      b.csproj

a.csproj的输出路径设置为'../../_bin',如果从a.csproj文件夹进行计数,则该输出路径仅在dir1上方 b.csproj的输出路径设置为"../../../_bin",该路径相同-如果从b.csproj计算,则大约为dir1

a.csproj has output path set to '../../_bin' which is just above dir1 if counted from a.csproj folder b.csproj has output path set to '../../../_bin' which is same - just about dir1 if counted from b.csproj

a.sln包含-a.csproj和b.csproj.

a.sln contains both - a.csproj and b.csproj.

当我运行msbuild时,我得到一个项目构建为'dir1/../../_ bin',b项目为'dir1/../../../_ bin'-项目文件的两个相对路径都是从解决方案文件位置开始计数,而不是从项目文件开始计数.

When I run msbuild I get a project build to 'dir1/../../_bin' and b project to 'dir1/../../../_bin' - both relative paths of projects files are counted from solution file location, not project files.

推荐答案

好吧,我能够找出导致此问题的原因.那是自定义的.targets文件,该文件在任何msbuild的开始都推断出SolutionDir属性. 我确实是通过使用MSBuild Explorer来发现的.在我看来,该工具非常有用-我不知道系统上的第三方.target文件.

Well, I was able to find out what was causing this. That was custom .targets file, which was inferring SolutionDir property at the start of any msbuild. I did find out that by using MSBuild Explorer. The tool proved to be very useful in my case - I was not aware of third party .target files on my system.

这篇关于MSBuild项目与解决方案的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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