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

标签 .net nuget nuget-package .net-standard nuget-spec

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

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

Solution structure

然后我有一个 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”窗口安装我的包时,引用显示为感叹号:

Package with error icon

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

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.

相比之下,如果我使用“添加引用”将 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>

由于某些原因,项目不喜欢版本信息。如果您进行初始的 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>

关于.net - 测试我的 NuGet 包,包出现 "project cannot be viewed in the object browser"错误,但包含的 DLL 没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48327355/

相关文章:

.net - 用于桌面应用程序的受 OpenID Connect 保护的 API

c# - net5 自包含 exe 缺少一些系统 DLL

nuget - 安装NuGet软件包时已添加了具有相同 key 的项目

c++ - nuget 包管理器包含在 VS 2015 中设置的目录在哪里?

xamarin - 更新 Nuget 导致异常未处理 : System. TypeLoadException

package - 如何在 sitecore 应用程序中为模块创建包

c# - 在 C# 中生成下一个可用的唯一名称

c# - 在 Multi-Tenancy .net 项目中实现角色的最佳方式是什么?

nuget - 如何使用 Nuget.exe 更新包

visual-studio-2010 - 网站的 NuGet 包还原