【问题标题】:Visual Studio Online - How to deal with nuget packages in this situation?Visual Studio Online - 在这种情况下如何处理 nuget 包?
【发布时间】:2016-02-18 14:58:28
【问题描述】:

我们最近从一个大的 SLN 文件转移到了多个文件。所以现在文件夹结构是这样的:

    • Solution1WebApp
      • 包(文件夹)
      • Project1(文件夹)
        • Project1.csproj
      • NuGet.config
      • Solution1.sln
    • Solution2 库
      • 包(文件夹)
      • Project1(文件夹)
        • Project1.csproj
      • Project2(文件夹)
        • Project2.csproj
      • NuGet.config
      • Solution2.sln
    • Solution3UnitTests
      • 包(文件夹)
      • Project1(文件夹)
        • Project1.csproj
      • Project2(文件夹)
        • Project2.csproj
      • Project3(文件夹)
        • Project3.csproj
      • NuGet.config
      • Solution3.sln

当我在 Visual Studio Online 中签入时,会触发构建。此构建配置为检索 nuget 包(因此未签入包文件夹)。

在Solution1的csproj文件中,我将所有指向包的路径都配置成这样:

<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
  <HintPath>..\..\Solution1WebApp\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
  <Private>True</Private>
</Reference>

但构建不断失败,我收到如下警告:

C:\Program Files (x86)\MSBuild\14.0\bin\amd64\Microsoft.Common.CurrentVersion.targets (1819, 5)  

    Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

而且我认为这些警告会导致以下异常:

The type or namespace name 'xxx' does not exist in the namespace 'yyy' (are you missing an assembly reference?)

所以我错过了什么吗?路径配置正确吗?

感谢您的帮助。

【问题讨论】:

  • 我认为将单元测试与主题分开不是一个好主意。你应该有两个解决方案,都包含单元测试和他们测试的代码......
  • 感谢 MrHinsh 的提示。为了清楚起见,我没有在那里提到它,但是网络应用程序正在引用单元测试项目,以便我们在打开网络应用程序时拥有所有可用的东西。

标签: msbuild visual-studio-2015 nuget-package azure-devops


【解决方案1】:

删除 packages.json 文件中提到的引用和项目。

将它们重新添加到解决方案中找不到文件的项目中。

保存并提交..为我工作。

【讨论】:

    【解决方案2】:

    好的,我找到了答案。包路径必须保留没有解决方案名称:

    <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
      <Private>True</Private>
    </Reference>
    

    在 VSO 构建定义中,我为每个解决方案添加了一个构建步骤(一个用于库,一个用于单元测试,一个用于 Web 应用程序)。

    这样,每个解决方案都在构建中,并且路径可以与我们 PC 上的本地路径保持一致。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多