[英]Relative paths in *.sln *.csproj files of c# .NetStandard project
Basically what the titles says.基本上是标题所说的。 I have a .NetStandard library which I am working on from both windows and linux.我有一个 .NetStandard 库,我正在 Windows 和 linux 上使用它。 My issue is that the reference paths are fully specified.我的问题是完全指定了参考路径。
Let's say in this case, I have 4 projects, each with their own folder and git repository.假设在这种情况下,我有 4 个项目,每个项目都有自己的文件夹和 git 存储库。 Project 1 references Project 2, 3, and 4;项目 1 引用项目 2、3 和 4; Project 2 and 3 reference project 4. The project folder structure is the same on both linux and windows however the user profile path variable differs.项目 2 和 3 参考项目 4。项目文件夹结构在 linux 和 windows 上是相同的,但是用户配置文件路径变量不同。
|-Project 1 | |-项目1 | |-Project 2 | |-项目2 | |-Project 3 | |-项目3 | |-Project 4 |-项目4
Can I specify relative paths in the .sln and .csproj files?我可以在 .sln 和 .csproj 文件中指定相对路径吗? If so how?如果是这样怎么办?
You can put paths that are relative to the .sln or .*proj in their respective files.您可以将相对于 .sln 或 .*proj 的路径放在它们各自的文件中。 I just opened up the .sln and .*proj our company is using an it looks like this.我刚刚打开了 .sln 和 .*proj 我们公司正在使用它,它看起来像这样。 These were auto generated by Visual Studio for us when adding projects to the solution.这些是 Visual Studio 在向解决方案添加项目时为我们自动生成的。
.sln .sln
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BL", "BL\BL.csproj", "{DF73AB2C-7331-49FD-8B4A-F71DAC66198A}"
EndProject
.*proj .*项目
<ProjectReference Include="..\..\..\BL\BL.csproj">
<Project>{df73ab2c-7331-49fd-8b4a-f71dac66198a}</Project>
<Name>BL</Name>
</ProjectReference>
In *.csproj
you can define properties.在*.csproj
您可以定义属性。
Define a property MyStuffDir
with the value $(ProjectDir)..\\..\\_MyFolder\\
.使用值$(ProjectDir)..\\..\\_MyFolder\\
定义属性MyStuffDir
。
<PropertyGroup>
<MyStuffDir>$(ProjectDir)..\..\_MyFolder\</MyStuffDir>
</PropertyGroup>
$(ProjectDir)
is the folder where the current csproj-file
is placed. $(ProjectDir)
是放置当前csproj-file
的文件夹。 Much more "Macros" available, see for example Build Events "PreBuildSteps" and "PostBuildSteps".更多可用的“宏”,参见例如构建事件“PreBuildSteps”和“PostBuildSteps”。 $(SolutionDir)
is where the sln-file
is placed. $(SolutionDir)
是放置sln-file
地方。
HINT I prefer the usage of $(ProjectDir)
, because it works also on CLI with msbuild, when I just build a single project and not the whole solution.提示我更喜欢使用$(ProjectDir)
,因为当我只构建一个项目而不是整个解决方案时,它也适用于带有 msbuild 的 CLI。
Use $(MyStuffDir)
inside an item group of the csproj-file, so you are relative to project level.在 csproj 文件的项目组中使用$(MyStuffDir)
,因此您是相对于项目级别的。
<ItemGroup>
<Compile Include="$(MyStuffDir)AssemblyVersion.cs">
<Link>Properties\AssemblyVersion.cs</Link>
</Compile>
</ItemGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.