Visual Studio 2017 csproj core file exclusion

ぐ巨炮叔叔 提交于 2019-11-29 02:26:01

问题


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.

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" />

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?


回答1:


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.

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

Longer answer:

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.

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".

To see what is happening under the hood, here are the default item settings for Microsoft.NET.Sdk and 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/aspnet/websdk/blob/rel/vs2017rtw/src/Web/Microsoft.NET.Sdk.Web.ProjectSystem.Targets/netstandard1.0/Microsoft.NET.Sdk.Web.ProjectSystem.props#L25-L40



来源:https://stackoverflow.com/questions/42803170/visual-studio-2017-csproj-core-file-exclusion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!