[英]New .csproj format - How to specify entire directory as “linked file” to a subdirectory?
With the new .csproj
format (as well as the old), it is possible to add files as linked outside of the project folder: 使用新的.csproj
格式(以及旧格式),可以将文件添加到项目文件夹之外的链接:
<EmbeddedResource Include="..\..\..\Demo\Sample.cs" Link="Resources\Sample.cs" />
It is also possible to use a glob pattern to include multiple files: 也可以使用glob模式来包含多个文件:
<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\\" />
The first two only create a single linked file (with exactly the name *.cs
and *
respectively). 前两个只创建一个链接文件(分别名称为*.cs
和*
)。 The third simply errors out. 第三个只是出错了。
Is there a way to combine globbing with linked files to a specific location in the target project? 有没有办法将globbing和链接文件组合到目标项目中的特定位置? If not, how can I link all the files in a directory without knowing how many or what their names are? 如果没有,我如何链接目录中的所有文件而不知道他们的名字有多少或者是什么?
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: 虽然以前可以在使用glob扩展时使用%(RecursiveDir)
元数据( Link="Resources\\%(RecursiveDir)%(Filename)%(Extension)"
),但2.0.0版本的.NET Core SDK允许使用新的LinkBase
元数据:
<EmbeddedResource Include="..\..\..\Demo\**\*.cs" LinkBase="Resources" />
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). 请注意,除了最近发布的VS 2017 15.3之外,您还需要安装2.0.0(并确保没有global.json
选择较低版本)。
It was introduced with this pull request which is probably the best documentation at the moment. 它引入了这个拉取请求 ,这可能是目前最好的文档。
I got this working for me (linking all svg-files in an external dir to a solution-subfolder) with a hint from this site . 我得到了这个为我工作(将外部目录中的所有svg文件链接到解决方案子文件夹),并提供了来自此站点的提示。 Only the %(Parent.Filename)
didn't work for me (got a CS1508), so I replaced with %(Filename)%(Extension)
. 只有%(Parent.Filename)
对我不起作用(得到CS1508),所以我用%(Filename)%(Extension)
替换。
<ItemGroup>
<Parent Include="C:\Path\To\My\SVG\Dir\*.svg" />
<EmbeddedResource Include="@(Parent)">
<Link>Resources\%(Filename)%(Extension)</Link>
</EmbeddedResource>
</ItemGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.