Search code examples
asp.net-corenugetnuget-packagenuget-spec

asp.net core nuspec project dependency


I got a couple of projects made with asp.net core that I wanted to export to NuGet. Everything was fine with the first version (0.9.0). But when I updated a package to 0.9.1, I started having version issues, cause the app started looking for all dependencies with version 0.9.1 (even though only one was updated and the others remained at 0.9.0)

Could anyone check my config and see where am I making my mistake? Thanks!

These are the errors I got:

FileLoadException: Could not load file or assembly 'Framework.Web, Version=0.9.1.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

FileLoadException: Could not load file or assembly 'Framework.Web, Version=0.9.1.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

This is my nuspec file:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
    <!-- Required elements-->
    <id>Framework.Web.Mvc</id>
    <version>0.9.1</version>
    <description>Framework web MVC library</description>
    <authors>Lucas Leite</authors>

    <!-- Optional elements -->
    <dependencies>
      <dependency id="Framework.Web" version="0.9.0" />
      <dependency id="Framework.Model" version="0.9.0" />
      <dependency id="Microsoft.AspNetCore.Localization.Routing" version="1.1.2" />
      <dependency id="Microsoft.AspNetCore.Mvc" version="1.1.3" />
    </dependencies>
    <!-- ... -->
  </metadata>
  <!-- Optional 'files' node -->
  <files>
    <file src="bin\Release\netcoreapp1.1\Framework.Web.Mvc.dll" target="lib\netcoreapp1.1" />
    <file src="bin\Release\netcoreapp1.1\Framework.Web.Mvc.xml" target="lib\netcoreapp1.1" />
    <file src="bin\Release\netcoreapp1.1\pt-BR\Framework.Web.Mvc.resources.dll" target="lib\netcoreapp1.1\pt-BR" />
  </files>
</package>

Solution

  • Try to change dependency version to (,0.9.0]:

    <dependency id="Framework.Web" version="(,0.9.0]" />
    

    Accordingly to Nuget dependency versioning,

    <!-- Accepts any version 0.9.0 and above -->
    <dependency id="Framework.Web" version="0.9.0" />
    

    and

    <!-- Accepts any version up below or include 0.9.0-->
    <dependency id="ExamplePackage" version="(,0.9.0]" />