新的.csproj格式-如何将整个目录指定为“链接文件"到子目录? [英] New .csproj format - How to specify entire directory as "linked file" to a subdirectory?
问题描述
使用新的.csproj
格式(以及旧的格式),可以将文件添加为链接到项目文件夹之外的文件:
With the new .csproj
format (as well as the old), it is possible to add files as linked outside of the project folder:
<EmbeddedResource Include="..\..\..\Demo\Sample.cs" Link="Resources\Sample.cs" />
还可以使用全局模式来包含多个文件:
It is also possible to use a glob pattern to include multiple files:
<EmbeddedResource Include="..\..\..\Demo\*.cs" />
但是您如何将两者结合起来?
But how do you combine the two?
-
<EmbeddedResource Include="..\..\..\Demo\*.cs" Link="Resources\*.cs" />
-
<EmbeddedResource Include="..\..\..\Demo\*.cs" Link="Resources\*" />
-
<EmbeddedResource Include="..\..\..\Demo\*.cs" Link="Resources\" />
<EmbeddedResource Include="..\..\..\Demo\*.cs" Link="Resources\*.cs" />
<EmbeddedResource Include="..\..\..\Demo\*.cs" Link="Resources\*" />
<EmbeddedResource Include="..\..\..\Demo\*.cs" Link="Resources\" />
前两个仅创建一个链接文件(分别分别具有名称*.cs
和*
).第三个只是出错了.
The first two only create a single linked file (with exactly the name *.cs
and *
respectively). The third simply errors out.
是否可以将glob和链接文件组合到目标项目中的特定位置?如果没有,如何链接目录中的所有文件而又不知道它们的名称是多少?
Is there a way to combine globbing with linked files to a specific location in the target project? If not, how can I link all the files in a directory without knowing how many or what their names are?
推荐答案
尽管以前使用glob扩展(Link="Resources\%(RecursiveDir)%(Filename)%(Extension)"
)时可以使用%(RecursiveDir)
元数据来实现,但.NET Core SDK 2.0.0版本允许使用新的LinkBase
元数据:
While this was previously possible using the %(RecursiveDir)
metadata when using glob expansion ( Link="Resources\%(RecursiveDir)%(Filename)%(Extension)"
), the 2.0.0 version of the .NET Core SDK allows the use of a new LinkBase
metadata:
<EmbeddedResource Include="..\..\..\Demo\**\*.cs" LinkBase="Resources" />
请注意,除了最近发布的VS 2017 15.3外,还需要安装2.0.0(并确保没有global.json
选择较低版本).
Note that you need to install the 2.0.0 in addition to the recently released VS 2017 15.3 (and ensure no global.json
selects a lower version).
它是通过此请求请求引入的,这可能是目前最好的文档
It was introduced with this pull request which is probably the best documentation at the moment.
这篇关于新的.csproj格式-如何将整个目录指定为“链接文件"到子目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!