【问题标题】:Generating correct nuspec file... NullReference exception when using assembly that's referencing TFS assemblies生成正确的 nuspec 文件...使用引用 TFS 程序集的程序集时出现 NullReference 异常
【发布时间】:2017-09-03 09:51:09
【问题描述】:

我正在尝试发布一个 nuget 包,其中包含一个引用另一个自定义程序集(这是另一个 nuget 包)的程序集,该程序集使用 TFS 程序集从 VSTS 获取工作项信息。

当我发布我的包并尝试使用此 dll 时,每当我的代码尝试访问 TFS 时,我都会收到 NullReference 异常。

明确地说,我已经发布了这个插件 nuget 包,其中包含:

Plugin.dll 程序集。

这个程序集有一些函数可以从 TFS 工作项中检索信息并执行任何工作

这些函数在 TFSUtilities.dll 程序集中(这也有自己的 nuget 包),它具有访问 TFS 的功能。

并且这个程序集(TFSUtilities.dll)引用了实际的 TFS 程序集,例如 'Microsoft.TeamFoundation.WorkItemTracking.Client'
'Microsoft.TeamFoundation.WorkItemTracking.Proxy'
'Microsoft.TeamFoundationTestManagement.Common' .... 等

因此,在发布我的 Plugin.dll nuget 包后,当我尝试从另一个解决方案引用此包并调用 Plugin.dll 中的函数来访问 TFS 工作项时,它只会在尝试访问 TFS 时给我 System.NullReferenceException。

我认为我没有生成正确的 nuspec 文件。下面是我的 plugin.dll 的 nuspec 文件的内容。

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>Plugin</id>
    <version>1.0.0.0</version>
    <title>Plugin</title>
    <authors>Custom</authors>
    <owners>BCustom</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Contains custom assemblies</description>
    <language>en-US</language>

    <dependencies>
      <dependency id="TFSUtilities" version="1.6.72" />
    </dependencies>
  </metadata>
  <files>
    <file src="..\bin\Release\Plugin.dll" target="lib\net452\Plugin.dll" />

    <file src="..\bin\Release\Plugin.dll" target="build\Plugin.dll" />
    <file src="..\bin\Release\TFSUtilities.dll" target="build\TFSUtilities.dll" />
      <file src="..\bin\Release\Microsoft.TeamFoundation.WorkItemTracking.Client.dll" target="build\Microsoft.TeamFoundation.WorkItemTracking.Client.dll" />
      <file src="..\bin\Release\Microsoft.TeamFoundation.Client.dll" target="build\Microsoft.TeamFoundation.Client.dll" />
      <file src="..\bin\Release\Microsoft.VisualStudio.Services.Client.dll" target="build\Microsoft.VisualStudio.Services.Client.dll" />
      <file src="..\bin\Release\Microsoft.VisualStudio.Services.Common.dll" target="build\Microsoft.VisualStudio.Services.Common.dll" />
      <file src="..\bin\Release\Microsoft.TeamFoundation.Common.dll" target="build\Microsoft.TeamFoundation.Common.dll" />
      <file src="..\bin\Release\Microsoft.VisualStudio.Services.WebApi.dll" target="build\Microsoft.VisualStudio.Services.WebApi.dll" />
  </files>
</package>

我在互联网上查找,看起来我可能需要添加更多库,如 WITDataStore64.dll 或更多,但我不太明白它在说什么。谁能帮我解决这个问题?仅供参考,我们的工作项目在 VSTS Online 上。

【问题讨论】:

  • 详细代码是多少?
  • 你能分享一下你得到的详细异常信息吗?

标签: c# .net dll tfs azure-pipelines


【解决方案1】:

请参考以下步骤:

  1. 创建类库项目(例如 TFSUtilities)
  2. 安装Microsoft.TeamFoundationServer.ExtendedClient
  3. 复制代码并粘贴到该项目中
  4. 构建这个项目
  5. 通过调用 Nuget.exe pack [项目文件路径 (TFSUtilities.csproj)] 来打包此项目

TFSUtilities.nuspec 代码:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>TFSUtilities</id>
    <version>1.0.0</version>
    <title>TFSUtilities</title>
    <authors>WS</authors>
    <owners>WS</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>TFS API</description>
    <copyright>Copyright ©  2017</copyright>
    <dependencies>
      <dependency id="Microsoft.TeamFoundationServer.ExtendedClient" version="15.112.1" />
      <dependency id="Newtonsoft.Json" version="8.0.3" />
    </dependencies>
  </metadata>
</package>
  1. 发布此包
  2. 创建类库项目(例如插件)
  3. 安装以前的包 (TFSUtilites)
  4. 编码
  5. 通过调用 Nuget.exe pack [项目文件路径 (Plugin.csproj)] 来打包此项目

插件.nuspec 代码:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>Plugin</id>
    <version>1.0.0</version>
    <title>Plugin</title>
    <authors>starain</authors>
    <owners>starain</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Description</description>
    <copyright>Copyright ©  2017</copyright>
    <dependencies>
      <dependency id="Newtonsoft.Json" version="8.0.3" />
      <dependency id="TFSUtilities" version="1.0.0" />
    </dependencies>
  </metadata>
</package>
  1. 将插件包安装到其他项目并使用它。

【讨论】:

  • TFSUtilities 项目已经安装了 ExtendedClients 包,但仍然失败。
  • @JNA 你的步骤是什么?你能分享一个 OneDrive 的简单项目吗?顺便说一句:我在我的答案中添加了 nuspec 代码,你可以检查一下。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多