Visual Studio 2017 csproj 核心文件排除 [英] Visual Studio 2017 csproj core file exclusion
问题描述
我已将 xproj
核心项目迁移到 csproj
.一切正常,但是我仍然遇到发布配置问题.基于文档:https://docs.microsoft.com/en-us/dotnet/articles/core/tools/project-json-to-csproj 我应该能够在发布期间排除文件.
I've migrated xproj
core projects to csproj
. All is working well, however I still have issues with publish configuration. Based on documentation:
https://docs.microsoft.com/en-us/dotnet/articles/core/tools/project-json-to-csproj I should be able to exclude files during publish.
我在 f 中添加了以下几行
I've added following lines to the f
<None Include="*.json" CopyToPublishDirectory="Never" />
<None Include="wwwroot***.map;wwwroot***.less;*.pdb" CopyToPublishDirectory="Never" />
<None Include="wwwroot***" CopyToPublishDirectory="PreserveNewest" />
但仍将 *.map
、.json
和 .less
文件复制到发布文件夹.我尝试了不同的顺序,但没有运气.
But still *.map
, .json
and .less
files are copied to publish folder. I tried different order no luck.
如何从发布中排除某些文件?
How to exclude certain files from publishing?
推荐答案
简短回答:请改用以下代码片段:
<ItemGroup>
<Content Update="***.map;***.less;*.json" CopyToPublishDirectory="Never" />
</ItemGroup>
您还可以将这些模式添加到DefaultItemExcludes"属性中.
You could also add these patterns to the "DefaultItemExcludes" property.
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);***.map;***.less;*.json</DefaultItemExcludes>
</PropertyGroup>
更长的答案:
Microsoft.NET.Sdk 和 Microsoft.NET.Sdk.Web 包括默认项目的设置.这些是项目文件夹中项目的 glob,应始终编译、嵌入、复制到输出等.有一些设置可以控制这一点,但没有很好的文档记录.
Microsoft.NET.Sdk and Microsoft.NET.Sdk.Web include settings for default items. These are globs for items in your project folder that should always be compiled, embedded, copied to output, etc. There are some settings to control this, but they are not well documented.
如果您想更改元数据值(例如作为默认 glob 已包含的项目的 CopyToPublishDirectory 设置,您必须使用更新"而不是包含".
If you want to change a metadata value (such as the CopyToPublishDirectory setting ) for an item already included by a default glob, you have to use "Update" instead of "Include".
要了解幕后发生的事情,这里是 Microsoft.NET.Sdk 和 Microsoft.NET.Sdk.Web 的默认项目设置
To see what is happening under the hood, here are the default item settings for Microsoft.NET.Sdk and Microsoft.NET.Sdk.Web
这篇关于Visual Studio 2017 csproj 核心文件排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!