0

I am consuming a NuGet package source in my dotnet project:

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

Source files are located in the contentFiles folder of the package, but are seen at the root folder of the project. This is causing strange behaviours with existing files.

How can I specify a project folder location for this package ?

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
ycrumeyrolle
  • 495
  • 4
  • 15
  • 1
    You fully answer to the question. Currently there is no way to control it if you are not the package owner. Thanks ! FYI, the NuGet package that was annoying was updated by its owner and is now located in its own folder. – ycrumeyrolle Feb 27 '19 at 09:47

1 Answers1

1

How to specify a specific folder for a NuGet source package?

I am afraid there is no such way you can specify a project folder location for this package directly. Because this behavior is determined by the internal file structure of the package. If we are not the author/owner of this package, we could not change the internal file structure of the package.

As a workaround, you can download that nuget package and re-pack that package and change the target folder to contentFiles/cs/netstandard2.0/Test/ with the .nuspec file:

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

Then add this package to your local nuget package feed, then use this your custom nuget package, all those .cs file are added to the Test folder:

enter image description here

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135