测试我的 NuGet 包,"project cannot be viewed in the object browser" 包错误,但包含的 DLL 没有

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

我正在制作一个针对 .Net Standard 1.3 和 .Net Fx 4.5 的 NuGet 包。

为此,我使用我的 NetStandard 版本的代码提供了一个解决方案,该版本经过了高度测试,我将两个 *.cs 文件复制到一个以 Fx 4.5 为目标的重复项目中 - 我不知道更好的方法。这是我第一次针对多个框架。

然后我有一个 nuspec 文件,看起来像这样(为简洁起见,元数据已被删除):

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

我可以用 nuget pack VillageSoftware.PathMatcher.nuspec

成功打包

我最初是使用本地 (C:\) 包源测试包,但此后将包推送到 NuGet.org

为了测试,我创建了一个新的 .Net Framework 4.5 控制台应用程序,当我使用 Install-Package 或 'Manage NuGet Packages' window 安装我的包时,引用显示为对此感叹:

双击引用会弹出错误消息框:

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.

相比之下,如果我使用 'Add Reference' 将 VillageSoftware.PathMatcher DLL 直接添加到 TestBed 项目中,它工作正常。

我的理论是包和宿主项目之间的框架不匹配,但我不知道为什么!包打包好,成功的 Install-Package 表明 NuGet 使用的是正确的库,而不是 NetStandard 版本。我认为我的库没有任何我在 nuspec 中遗漏的依赖项。

为什么会这样?

我可以回答正在发生的事情。我继续将您的包安装到测试解决方案中。我看到的结果和你看到的一样,引用无效。然后我比较了安装后参考的情况,然后手动删除并再次添加参考。

从我的 csproj 文件,安装后(不工作):

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

手动安装后(工作):

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

由于某种原因,项目不喜欢版本信息。如果您采用初始 post-nuget 安装并将版本修改为 Version=1.0.1(从版本末尾删除 .0),您会发现参考有效。对于为什么会发生这种情况,我没有很好的答案,但您可能想要更改 AssemblyInfo.cs 中的版本控制以匹配 nuget 包。

最终修正结果:

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