简体   繁体   中英

Visual Studio incorrectly packs wwwroot in NuGet package

I'm currently upgrading from the *.xproj with project.json format to the *.csproj file formats, leveraging the newer Visual Studio 2017 tooling. Below is the version I'm on for both the IDE and the SDK / .NET Core CLI:

Visual Studio Version

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 Core 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

With that said, I'm curious how can I exclude wwwroot from my NuGet package that is created without relying on a .nuspec . Is this possible?

.csproj

Here is my .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>

Package Content

Here is an image of the package contents:

在此输入图像描述

Ideally, I want to content to resemble exclude the content and contentFiles bits and instead just be the lib with the .exe .

You can modify the content items in the project file to set the Pack metadata to false for either just the wwwroot folder or for all content items:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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