Skip to content

Instantly share code, notes, and snippets.

@WillSams
Last active April 19, 2020 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillSams/1dd35bb16518bfd1206a104a6c7c8fa8 to your computer and use it in GitHub Desktop.
Save WillSams/1dd35bb16518bfd1206a104a6c7c8fa8 to your computer and use it in GitHub Desktop.
.NET Core Create & Use Local .Nuget Package (/w content)

Hard to find good information on the Interwebs about this. See below on how to do this correctly:

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <PackageId>Otter</PackageId>
    <Version>0.9.6-20200417</Version>
    <IncludeAssets>all</IncludeAssets>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="CONSOLA.TTF" CopyToOutputDirectory="Always">
      <PackageCopyToOutput>true</PackageCopyToOutput>
      <IncludeInPackage>true</IncludeInPackage>
    </Content>
    <Content Include="otterlogo.png" CopyToOutputDirectory="Always">
      <PackageCopyToOutput>true</PackageCopyToOutput>
      <IncludeInPackage>true</IncludeInPackage>
    </Content>
  </ItemGroup>

dotnet pack --configuration Release # run this comman to build Manually move the package to a package store within the project your want. For me, it's been {solution root}/resources/packages

In the project you want to use the package, explicitly name your package stores (only if you want to add from local store and not the current NuGet.org hosted version of Otter):

<PropertyGroup>
  <RestoreSources>$(RestoreSources);../../resources/packages;https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>

Then, at the command-line: dotnet add package <yourpackage> --version 0.9.6-20200417

If you are still having issues but you already referenced an unwanted version of your package, go to your global package store on your machine (for example ~/.nuget/packages) and delete the package you might have added there before trying to add the package as a reference again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment