Skip to content

Instantly share code, notes, and snippets.

@WillSams

WillSams/nuget.md

Last active Apr 19, 2020
Embed
What would you like to do?
.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
You can’t perform that action at this time.