c# - Azure Devops 上的 Net Core 3.0 SDK Preview 9 的 Visual Studio 构建失败

标签 c# visual-studio .net-core azure-devops azure-pipelines

整个周末我都在为这个问题苦苦挣扎。

我无法成功构建 Net Core 3 SDK Preview 9(2019 年 9 月 4 日发布)。

我设置了一个管道,专门用于:

  1. 使用新的 SDK
  2. 使用新的 SDK 实现一个 global.json 文件
  3. 使用Nuget 5.x和Nuget restore正确获取预览包
  4. Visual Studio 构建解决方案

我在构建阶段 (4) 遇到以下错误:

Error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.

Error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.

在第 2 步中实现 global.json 之前,我最初在 Nuget 恢复阶段 (3) 遇到了同样的错误,所以我知道 global.json 是被正确引用。

管道 YAML:

pool:
  name: Azure Pipelines
  demands:
  - msbuild
  - visualstudio

steps:
- task: UseDotNet@2
  displayName: 'Use .Net Core sdk 3.0.100-preview9-014004'
  inputs:
    version: '3.0.100-preview9-014004'
    includePreviewVersions: true

- powershell: |
   $globaljson = '{"sdk": {"version": "3.0.100-preview9-014004"}}';
   $globaljson | out-file './test.app/global.json' -Encoding UTF8
  displayName: 'Global Json'

- task: NuGetToolInstaller@1
  displayName: 'Use NuGet 5.x'
  inputs:
    versionSpec: 5.x
    checkLatest: true

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '$(Parameters.solution)'

- task: VSBuild@1
  displayName: 'Build solution **\*.sln'
  inputs:
    solution: '$(Parameters.solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

enter image description here

最佳答案

以下对我有用。

设置以下变量:

variables:
  MSBuildSDKsPath: 'C:\\hostedtoolcache\\windows\\dotnet\\sdk\\3.0.100-preview9-014004\\sdks'

设置全局json

  - task: PowerShell@2
    displayName: 'Global Json'
    inputs:
      targetType: 'inline'
      script: 'dotnet new globaljson --sdk-version 3.0.100-preview9-014004'

另外,需要注意一件事,我在使用 Nuget 5 时遇到了问题。我使用了 Nuget 4.7.1

关于c# - Azure Devops 上的 Net Core 3.0 SDK Preview 9 的 Visual Studio 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57852267/

相关文章:

c# - 关闭在另一个线程中创建的表单

c# - 如何获取给定年份的周数

visual-studio - 命令行参数

visual-studio - Visual Studio 2008宏获取源码

visual-studio - ReSharper 9 - 快捷键 Alt+Enter 在 VS 2015 中不起作用

c# - 运行时编译期间收到 “You must add a reference to assembly ' netstandard'”错误

c# - 如何在 Asp.Net webforms 中实现插件架构

c# - 使用System.Text.Json反序列化匿名类型

visual-studio-2015 - 在 VS2015 中保存 AWS Lambda 项目时出现问题

.net - 错误 NU1605 检测到软件包降级