azure-devops - 混合核心/标准解决方案的 Azure devops 构建管道 nuget 包参考错误
问题描述
我们有多个项目解决方案,混合了使用 Visual Studio 2019 开发的 .NET Core 和 Standard,并且需要使用 Azure devops 来构建/发布管道。
解决方案的结构大致如下:
Solution A
|--Product A (.NET Standard)
| |---- References project Class Library A
|
|--Product B (.NET Core)
| |---- References project Class Library B
|
|--Class Library A(.NET Standard)
|--Class Library B(.NET Core)
|---- References project Class Library A
产品 A - 没有问题:
- 将类库 A 中使用的 NuGet 包添加到产品 A
- 在文件夹中恢复产品 A 的包并运行构建
产品 B - 看起来我在某处遗漏了一些东西: 恢复和构建步骤 YAML - 我正在使用 .Net Core App 的标准模板:
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: restore
projects: '**/*.csproj '
restoreDirectory: '..\packages'
- task: DotNetCoreCLI@2
displayName: Build
inputs:
projects: Product B/Product B.csproj
arguments: '--configuration $(BuildConfiguration)'
workingDirectory: Product B
并且构建失败并出现多个错误,例如以下错误:
2021-10-27T23:14:59.7887932Z ##[warning]C:\Program Files\dotnet\sdk\5.0.402\Microsoft.Common.CurrentVersion.targets(2203,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json, Version=12.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.
2021-10-27T23:14:59.7892028Z C:\Program Files\dotnet\sdk\5.0.402\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json, Version=12.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. [D:\a\1\s\Class Library A\Class Library A.csproj]
##[error]Class Library A\Models\Model.cs(2,7): Error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
D:\a\1\s\Class Library A\Models\Model.cs(2,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) [D:\a\1\s\Class Library A\Class Library A.csproj]
我如何告诉构建使用还原任务中的包?我试图添加参数 --source ..\packages 来构建任务 - 没有用。
我想我可以对产品 A 做同样的技巧:将类库 A 和类库 B 中使用的 NuGet 包添加到产品 B,但我希望它可能是不同的方式(它需要添加对 70 多个包的引用)
ps:我知道,我可以将类库 A 制作成 NuGet 包并从私有 Artifact 提要中使用它进行构建,但我更愿意保留项目引用以简化调试过程。
解决方案
推荐阅读
- html - 折叠按钮不动
- javascript - 如何在 react-native-snap-carousel 中使轮播循环?
- google-apps-script - 有没有办法在谷歌应用脚本的文档中添加唯一标识符?
- android - Expo Cli - 不变违规:requireNativeComponent:在 UIManager 中找不到“RNCSafeAreaProvider”
- amazon-web-services - 如何使用 cli 在云端分发中更新 lambda@edge arn
- java - 检查方法是否使用 while 或 for 循环(Java)
- python - 如何正确提取 Keras ConvNet 权重矩阵以在 Excel 中使用?
- visual-studio-code - 从 local.settings.json 读取很热
- unit-testing - 在嵌入式目标中使用 Google 测试?
- python - sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) 没有这样的列:user.name