Visual Studio错误地将wwwroot打包到NuGet包

时间:2017-11-28 18:08:13

标签: c# nuget .net-core visual-studio-2017

我目前正在使用*.xproj project.json格式升级到*.csproj文件格式,并利用较新的Visual Studio 2017工具。下面是我在IDE和SDK / .NET Core CLI上的版本:

Visual Studio版本

Microsoft Visual Studio Community 2017 
Version 15.4.3
VisualStudio.15.Release/15.4.3+27004.2008
Microsoft .NET Framework
Version 4.7.02558

SDK / .NET核心CLI

.NET Command Line Tools (2.0.2)

Product Information:
 Version:            2.0.2
 Commit SHA-1 hash:  a04b4bf512

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.3.9600
 OS Platform: Windows
 RID:         win81-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.2\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

话虽如此,我很好奇如何从不依赖wwwroot创建的NuGet包中排除.nuspec。这可能吗?

.csproj

这是我的.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>        
    <!-- omitted for brevity -->
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="wwwroot\**\*;node_modules" />
    <EmbeddedResource Include="Views\**" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
    <None Update="NLog.config">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <PackagePath>lib/net461/</PackagePath>
      <Pack>true</Pack>
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>
    <None Update="wwwroot\**\*">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>
  </ItemGroup>

  <ItemGroup>
    <!-- package references, omitted for brevity -->
  </ItemGroup>

</Project>

包内容

以下是包装内容的图片:

enter image description here

理想情况下,我希望内容类似于排除contentcontentFiles位,而只是lib.exe

1 个答案:

答案 0 :(得分:3)

您可以修改项目文件中的内容项,将Pack元数据设置为false,仅用于wwwroot文件夹或所有内容项目:

<ItemGroup>
  <!-- only exclude wwwroot items from package -->
  <Content Update="wwwroot/**" Pack="false" />

  <!-- Exclude all content from package (e.g. appsettings.json) -->
  <Content Update="@(Content)" Pack="false" />
</ItemGroup>