Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

msbuild - How do I exclude files/folders from a .NET Core/Standard project?

In .NET Core and .NET Standard projects, if you put files and folders within the project directory, they are automatically picked up by Visual Studio; essentially they are part of the project.

What if I have files/folders in there that aren't really part of the project itself (in terms of code or content) - short of removing them altogether, is there a way I can exclude them from the project as I can with projects targeting the full .NET Framework?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are also a few things you can do in the csproj files to make sure the files aren't picked up:

1) Make sure none of the globbing patterns that look for "project items" pick up the files:

<PropertyGroup>
  <DefaultItemExcludes>$(DefaultItemExcludes);your_nonproj.file;a***.pattern</DefaultItemExcludes>
</PropertyGroup>

2) Remove items explicitly:

<ItemGroup>
  <None Remove="hidden.file" />
  <Content Remove="wwwrootlib***" />
</ItemGroup>

Note that, on large directories (number of files), using DefaultItemExcludes with the folder** pattern is a lot faster since msbuild will skip walking the directory entirely. Using a remove for this will still let msbuild spend quite some time discovering files.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...