我創建了一個簡單的 ASP.NET CORE 6 Web API。然后我把它推到了 Github。當我嘗試在Azure Devops 中創建管道時,出現錯誤。
C:\Program Files\dotnet\sdk\5.0.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET
.TargetFrameworkInference.targets(141,5): error NETSDK1045: The current .NET SDK does not support
targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports
.NET 6.0.
我剛剛下載了 VS 2022 社區版。我已經安裝了 .Net SDK 6。這是我的 csproj 檔案
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
</Project>
我選擇了 Azure devops 建議的內容,所以這是我的 yml 檔案
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package
/p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
我已經按照
uj5u.com熱心網友回復:
我選擇了 Azure devops 建議的內容,所以這是我的 yml 檔案
不幸的是,這很容易混淆,因為 Microsoft 的命名絕不是一致的。為此,您需要使用 .NET Core 指南:構建、測驗和部署 .NET Core 應用程式
為了節省您的時間,這里有一個簡單的 YAML 管道來構建 ASP.NET Core 應用程式:
trigger:
branches:
include:
- master
# Setup pipeline-level variables to keep things DRY
variables:
configuration: Release
projects: '**/*.csproj'
publish_dir: $(Build.ArtifactStagingDirectory)
vm_image: ubuntu-latest
stages:
- stage: Build
jobs:
- job: dotnet
displayName: .NET
pool:
vmImage: $(vm_image)
# Run builds in latest .NET 6 SDK container (Debian 11)
# This simplifies things and allows to easily target different SDKs:
# https://hub.docker.com/_/microsoft-dotnet-sdk
container: mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim
workspace:
clean: all
# Build tasks a separated (restore/build/test/publish)
# to make it easier to catch/debug issues
steps:
- task: DotNetCoreCLI@2
displayName: .NET | Restore [$(configuration)]
inputs:
command: restore
projects: $(projects)
- task: DotNetCoreCLI@2
displayName: .NET | Build [$(configuration)]
inputs:
command: build
projects: $(projects)
arguments: --configuration $(configuration) --no-restore
- task: DotNetCoreCLI@2
displayName: .NET | Test [$(configuration)]
inputs:
command: test
projects: $(projects)
publishTestResults: true
arguments: --configuration $(configuration) --no-restore --no-build
- task: DotNetCoreCLI@2
displayName: .NET | Publish [$(configuration)]
inputs:
command: publish
publishWebProjects: true
zipAfterPublish: true
modifyOutputPath: true
arguments: --configuration $(configuration) --output $(publish_dir) --no-restore --no-build
# Publish zipped build results so they can be downloaded from the pipeline UI
- publish: $(publish_dir)
displayName: Artifact | Publish
artifact: $(Build.DefinitionName)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/364425.html
標籤:asp.net核心 azure-devops 天蓝色管道
