简体   繁体   English

Visual Studio 2017 csproj核心文件排除

[英]Visual Studio 2017 csproj core file exclusion

I've migrated xproj core projects to csproj . 我已将xproj核心项目迁移到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. 基于文档: https//docs.microsoft.com/en-us/dotnet/articles/core/tools/project-json-to-csproj我应该能够在发布期间排除文件。

I've added following lines to the f 我在f中添加了以下行

<None Include="*.json" CopyToPublishDirectory="Never" />
<None Include="wwwroot\**\*.map;wwwroot\**\*.less;*.pdb" CopyToPublishDirectory="Never" />
<None Include="wwwroot\**\*" CopyToPublishDirectory="PreserveNewest" />

But still *.map , .json and .less files are copied to publish folder. 但仍然将*.map.json.less文件复制到发布文件夹。 I tried different order no luck. 我试过不同的顺序没有运气。

How to exclude certain files from publishing? 如何从发布中排除某些文件?

Short answer: use the following snippets instead: 简短回答:使用以下代码段:

<ItemGroup>
  <Content Update="**\*.map;**\*.less;*.json" CopyToPublishDirectory="Never" />
</ItemGroup>

You could also add these patterns to the "DefaultItemExcludes" property. 您还可以将这些模式添加到“DefaultItemExcludes”属性中。

<PropertyGroup>
  <DefaultItemExcludes>$(DefaultItemExcludes);**\*.map;**\*.less;*.json</DefaultItemExcludes>
</PropertyGroup>

Longer answer: 更长的回答:

Microsoft.NET.Sdk and Microsoft.NET.Sdk.Web include settings for default items. Microsoft.NET.Sdk和Microsoft.NET.Sdk.Web包含默认项的设置。 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. 这些是项目文件夹中项目的全局,应始终进行编译,嵌入,复制到输出等。有一些设置可以控制它,但它们没有很好地记录。

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". 如果要更改已包含在默认glob中的项目的元数据值 (例如CopyToPublishDirectory设置),则必须使用“Update”而不是“Include”。

To see what is happening under the hood, here are the default item settings for Microsoft.NET.Sdk and Microsoft.NET.Sdk.Web 要了解幕后发生的情况,请参阅Microsoft.NET.Sdk和Microsoft.NET.Sdk.Web的默认项目设置。

https://github.com/dotnet/sdk/blob/dev15.1.x/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.DefaultItems.props#L19-L27 https://github.com/dotnet/sdk/blob/dev15.1.x/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.DefaultItems.props#L19-L27

https://github.com/aspnet/websdk/blob/rel/vs2017rtw/src/Web/Microsoft.NET.Sdk.Web.ProjectSystem.Targets/netstandard1.0/Microsoft.NET.Sdk.Web.ProjectSystem.props#L25-L40 https://github.com/aspnet/websdk/blob/rel/vs2017rtw/src/Web/Microsoft.NET.Sdk.Web.ProjectSystem.Targets/netstandard1.0/Microsoft.NET.Sdk.Web.ProjectSystem.props# L25-L40

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM