Can I use both wildcard and Link element inside the Compile element?

点点圈 提交于 2019-12-05 02:58:27
<Content Include="..\..\SomeDirectory\**\*.xml">
  <Link>SomeLinkDirectoryOfYourChoosing\%(Filename)%(Extension)</Link>
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

For the sake of others, here's the answer plus the comment from Dean and Miserable Variable, which I found useful:

I have two projects, and I need to include *.xsd from one in the other, without copying the files or having to update the referencing csproj file every time a new XSD is added to the first.

The solution was to add the following to the csproj file

  <Content Include="..\BusinessLayer\Schemas\*.xsd">
    <Link>Contract\Schemas\xxx.xsd</Link>
  </Content>

Note xxx.xsd, you have to give a dummy filename in the Link element. It just gets replaced.

Also, you can include all sub folders with:

  <Content Include="..\BusinessLayer\Schemas\**\*.xsd">
    <Link>Contract\Schemas\ThisTextDoesntMatter</Link>
  </Content>

And files of all type (useful for pulling in CSS/JS/Style folders from 3rd parties) with:

  <Content Include="..\PresentationLayer\CustomerStyle\**\*.*">
    <Link>CustomerStyle\placeHolder</Link>
  </Content>

Others have suggested the using the Link attribute with placeholders, which indeed works. However, Microsoft has implemented a new attribute (which isn't in any of my code completion suggestions), named LinkBase, shown below.

<Compile Include="..\SomeDirectory\*.cs" LinkBase="SomeDirectoryOfYourChoosing" />

Sources:

To include subfolders:

<ItemGroup>
  <Compile Include="..\SomeExternalFolder\**\*.cs" LinkBase="YourProjectFolder" />
</ItemGroup>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!