Dir1\F...">

Can I use a wildcard and Link element inside a Compile element?

In the .csrpoj file, if I have

 <Compile Include="c:\path\File1.cs"> <Link>Dir1\File1.cs</Link> </Compile> 

Visual Studio then displays this file as a shortcut in the Dir1 folder in Solution Explorer.

If i have

 <Compile Include="c:\path\*.cs"></Compile> 

Then all .cs files are displayed as shortcuts in the top-level Solution Explorer:

Is there a way to include all the files in some folder and then display under a subfolder? Omitting the file name in the Link element does not work:

 <Compile Include="c:\path\*.cs"> <Link>Dir1\</Link> </Compile> 

Files are still displayed at the top level.

How to include all files in a folder and use the Link element? The reason I need to include files from several folders, and some of them have the same name. Two files at the top level cannot have the same name.

Any other way to achieve this?


I am new to the Visual Studio platform. Sorry in advance for any stupid questions.

+6
source share
4 answers
 <Content Include="..\..\SomeDirectory\**\*.xml"> <Link>SomeLinkDirectoryOfYourChoosing\%(Filename)%(Extension)</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> 
+9
source

For others, here is the answer plus a comment from Dean and Miserable Variable, which I found useful:

I have two projects, and I need to include * .xsd from one to another without copying files or updating the csproj reference file each 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> 

Pay attention to xxx.xsd, you must specify a dummy file name in the Link element. It is simply being replaced.

In addition, you can enable all subfolders using

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

And files of all types (useful for pulling into third-party CSS / JS / Style folders) with

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

Others have suggested using the Link attribute with placeholders, which really works. However, Microsoft has introduced a new attribute (which is not found in any of my code completion suggestions) called LinkBase , shown below.

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

Sources:

+1
source

To enable subfolders:

 <ItemGroup> <Compile Include="..\SomeExternalFolder\**\*.cs" LinkBase="YourProjectFolder" /> </ItemGroup> 
0
source

Source: https://habr.com/ru/post/1334632/


All Articles