简体   繁体   English

新的.csproj格式 - 如何将整个目录指定为“链接文件”到子目录?

[英]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? 但是你如何将两者结合起来呢?

What I Tried 我试过的

  1. <EmbeddedResource Include="..\\..\\..\\Demo\\*.cs" Link="Resources\\*.cs" />
  2. <EmbeddedResource Include="..\\..\\..\\Demo\\*.cs" Link="Resources\\*" />
  3. <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.

相关问题 避免使用新的csproj格式设置“复制到输出目录” - Avoid to set Copy To Output Directory with new csproj format 如何使用MSBuild将链接文件添加到csproj文件。 (3.5框架) - How to add a linked file to a csproj file with MSBuild. (3.5 Framework) Visual Studio 2017 RC如何在csproj文件中指定发布选项 - Visual Studio 2017 RC How to specify Publishing Options in the csproj file 将MSBuild与新的csproj格式一起使用 - Using MSBuild with the new csproj format RegistryKey 更改为新的 csproj 格式 - RegistryKey changed with new csproj Format 如何检测到包含在 new.csproj SDK 格式中的 .cs 文件? - How .cs-files detected for inclusion in the new .csproj SDK format? 如何从Visual Studio扩展和新的csproj格式获取IntermediateOutputPath - How to get IntermediateOutputPath from Visual Studio extension and new csproj format 如何在Visual Studio 2017项目(新的.csproj文件格式)中设置`OutputPath`,而不会使目标框架混乱已解析的路径? - How do I set `OutputPath` in a Visual Studio 2017 project (new .csproj file format) without the target framework cluttering the resolved path? 如何在VS 2017中将csproj文件更改回旧格式 - How to change the csproj file back to old format in VS 2017 如何设置 .csproj 的根目录? - How to set the root directory for a .csproj?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM