Visual studio 如何为NuGet源程序包指定特定文件夹?

Visual studio 如何为NuGet源程序包指定特定文件夹?,visual-studio,.net-core,nuget,Visual Studio,.net Core,Nuget,我正在使用dotnet项目中的NuGet程序包源: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>netstandard2.0</TargetFrameworks> </PropertyGroup> <ItemGroup> <PackageReference Include="Mic

我正在使用dotnet项目中的NuGet程序包源:

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

  <PropertyGroup>        
    <TargetFrameworks>netstandard2.0</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Bcl.Json.Sources" Version="4.6.0-preview.19073.11">
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
  </ItemGroup>

</Project>

netstandard2.0
全部的
源文件位于包的
contentFiles
文件夹中,但可以在项目的根文件夹中看到。 这会导致现有文件出现奇怪的行为

如何为此包指定项目文件夹位置

如何为NuGet源程序包指定特定文件夹

恐怕您无法直接为此包指定项目文件夹位置。因为这种行为是由包的内部文件结构决定的。如果我们不是此包的作者/所有者,则无法更改包的内部文件结构

作为一种解决方法,您可以下载该nuget软件包并重新打包该软件包,然后使用
.nuspec
文件将目标文件夹更改为
contentFiles/cs/netstandard2.0/Test/

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata minClientVersion="2.12">
    <id>Microsoft.Bcl.Json.Sources</id>
    <version>4.6.0-preview.19073.11</version>
    <title>Microsoft.Bcl.Json.Sources</title>
    <authors>Microsoft</authors>
    <owners>microsoft,dotnetframework</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <licenseUrl>https://github.com/dotnet/corefx/blob/master/LICENSE.TXT</licenseUrl>
    <projectUrl>https://dot.net/</projectUrl>
    <iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
    <description>Add Description Here</description>
    <releaseNotes>https://go.microsoft.com/fwlink/?LinkID=799421</releaseNotes>
    <copyright>© Microsoft Corporation. All rights reserved.</copyright>
    <serviceable>true</serviceable>

    <contentFiles>
      <files include="cs/netstandard2.0/BitStack.cs" buildAction="content" flatten="true" copyToOutput="true"/>
      <files include="cs/netstandard2.0/xx.cs" buildAction="content" flatten="true" copyToOutput="true"/>
       ...
    </contentFiles>

  </metadata>

    <files>
      <file src="build/netstandard2.0/Microsoft.Bcl.Json.Sources.targets" target="build" />
      <file src="build/netstandard2.0/Strings.resx" target="build" />
      <file src="contentFiles/cs/netstandard2.0/BitStack.cs" target="contentFiles/cs/netstandard2.0/Test/" />
      <file src="contentFiles/cs/netstandard2.0/xx.cs" target="contentFiles/cs/netstandard2.0/Test/" />
      ...
    </files>

</package>

Microsoft.Bcl.Json.Sources
4.6.0-preview.19073.11
Microsoft.Bcl.Json.Sources
,然后使用此自定义nuget软件包,所有这些
.cs
文件将添加到
测试
文件夹:


希望这能有所帮助。

你完全回答了这个问题。如果您不是包的所有者,目前无法控制它。谢谢仅供参考,令人讨厌的NuGet软件包已由其所有者更新,现在位于其自己的文件夹中。