Visual Studio 2017 csproj核心文件排除 [英] Visual Studio 2017 csproj core file exclusion

查看:93
本文介绍了Visual Studio 2017 csproj核心文件排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将 xproj 核心项目迁移到 csproj 。一切工作正常,但是发布配置仍然存在问题。基于文档:
https ://docs.microsoft.com/zh-cn/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

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

但仍 *。map ,<$将c $ c> .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?

推荐答案

简短答案:而是使用以下代码段:

Short answer: use the following snippets instead:

<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包含默认项目的设置。这些是项目文件夹中的项目的全局标记,应始终对其进行编译,嵌入,复制到输出等。有一些设置可控制此设置,但记录不充分。

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.

如果您要更改元数据值(例如作为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

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

这篇关于Visual Studio 2017 csproj核心文件排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆