Search code examples
.netnugetnuget-package.net-standardnuget-spec

Testing my NuGet package, "project cannot be viewed in the object browser" error with package but not with the comprising DLL


I am making a NuGet package which targets .Net Standard 1.3 and .Net Fx 4.5.

To do this, I have a solution with my NetStandard version of the code, which is highly tested, and I copy across the two *.cs files to a duplicate project which targets Fx 4.5 - I didn't know a better way to do it. This is my first time targeting multiple frameworks.

Solution structure

I then have a nuspec file which looks like this (metadata has been snipped for brevity):

<?xml version="1.0"?>
<package>
  <metadata>
    <snip/>
  </metadata>
  <files>
    <file src="VillageSoftware.PathMatcher-NetFx45\bin\Release\VillageSoftware.PathMatcher-NetFx45.dll" target="lib\net45\VillageSoftware.PathMatcher.dll" />
    <file src="VillageSoftware.PathMatcher\bin\Release\netstandard1.3\VillageSoftware.PathMatcher.dll" target="lib\netstandard1.3\VillageSoftware.PathMatcher.dll" />
  </files>
</package>

I can successfully pack this with nuget pack VillageSoftware.PathMatcher.nuspec

I was initially testing the package using a local (C:\) package source but have since pushed the package to NuGet.org

To test, I created a new .Net Framework 4.5 Console App, and when I install my package using either Install-Package or the 'Manage NuGet Packages' window, the reference shows up with an exclamation on it:

Package with error icon

Double clicking the reference throws up an error message box:

This project cannot be viewed in the object browser because it is unavailable or not yet built. Please ensure that the project is available and built.

Contrastingly, if I use 'Add Reference' to add the VillageSoftware.PathMatcher DLL directly to the TestBed project, it works fine.

My theory is that the frameworks between the package and the host project are not matching up, but I don't know why! The package packs up fine, and the successful Install-Package shows that NuGet is using the correct lib, not the NetStandard version. I don't think my lib has any dependencies which I've missed in the nuspec.

Why is this happening?


Solution

  • I can answer the what it is happening. I went ahead and installed your package into a test solution. I saw the same result that you see, the reference is invalid. I then took a comparison of how the reference was after install then manually removed and added the reference again.

    From my csproj file, after install (not working):

        <Reference Include="VillageSoftware.PathMatcher, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
            <HintPath>..\packages\VillageSoftware.PathMatcher.1.0.1\lib\net45\VillageSoftware.PathMatcher.dll</HintPath>
        </Reference>
    

    After manual install (working):

        <Reference Include="VillageSoftware.PathMatcher">
            <HintPath>..\packages\VillageSoftware.PathMatcher.1.0.1\lib\net45\VillageSoftware.PathMatcher.dll</HintPath>
        </Reference>
    

    For some reason, the project does not like the version information. If you take the initial post-nuget install and modify the version to Version=1.0.1 (remove the .0 from the end of version), you will find that the reference works. I don't have a good answer for why this is happening, but you may want to changing the versioning in your AssemblyInfo.cs to match the nuget package.

    Final result to fix:

        <Reference Include="VillageSoftware.PathMatcher, Version=1.0.1, Culture=neutral, processorArchitecture=MSIL">
            <HintPath>..\packages\VillageSoftware.PathMatcher.1.0.1\lib\net45\VillageSoftware.PathMatcher.dll</HintPath>
        </Reference>