close
以下文章為我遇到把dotent core webapi專案包成docker出現的問題
我原本的CI build code如下
# 輸入 rhel.7-x64 Docker Image
> dotnet restore -r rhel.7-x64
> dotnet publish --no-restore -f netcoreapp2.2 -c Release -r rhel.7-x64 --self-contained false /p:PublishWithAspNetCoreTargetManifest=false
> docker build -t pushproxy:v1 .
|
但是執行後,卻出現如下情況....
The specified framework 'Microsoft.AspNetCore.App', version '2.2.0' was not found. - Check application dependencies and target a framework version installed at: /opt/rh/rh-dotnet22/root/usr/lib64/dotnet/ - Installing .NET Core prerequisites might help resolve this problem: http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409 - The .NET Core framework and SDK can be installed from: https://aka.ms/dotnet-download It was not possible to find any compatible framework version |
真是見鬼了!!
完全按照openshift官網的說明文字居然會執行失敗
經過半天的努力後....我放棄了 晚上先去打球
今天早上重新整理思緒~~
使用 dotnet --info 去查CI SDK docker image的環境到底是?
microsoft/dotnet:2.2-sdk
|
然後再看一下我自己電腦內的SDK環境
dotnet --info .NET Core SDK (反映任何 global.json): Version: 2.2.101 Commit: 236713b0b7 執行階段環境: OS Name: Windows OS Version: 10.0.15063 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.2.101\ Host (useful for support): Version: 2.2.0 Commit: 1249f08fed .NET Core SDKs installed: 2.0.2 [C:\Program Files\dotnet\sdk] 2.1.4 [C:\Program Files\dotnet\sdk] 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.302 [C:\Program Files\dotnet\sdk] 2.1.403 [C:\Program Files\dotnet\sdk] 2.2.101 [C:\Program Files\dotnet\sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] |
似乎發現原因了!!!
總之就重新到官網下載最新的sdk
然後問題就解決啦
才怪
restore指令過關
但publish反而就發生錯誤 囧
dotnet publish --no-restore -f netcoreapp2.2 -c Release -r rhel.7-x64
Microsoft (R) Build Engine for .NET Core 15.9.20+g88f5fadfbe 版 Copyright (C) Microsoft Corporation. 著作權所有,並保留一切權利。 D:\00_CODE\dotnetCore\chtpushproxy\PushProxy.csproj : error : NETSDK1061: 專案是使用 Microsoft.NETCore.App 版本 2.2.0 還原的,但依照目前設定,使用的版本會是 2.2.1。若要解決此問題,請確認用於還原與後續作業 (例如建置或發佈) 的設定相同。一般而言,若在建置或發佈期間設 |
感謝網路上中國人的幫忙
.csproj檔案加入以下資訊,強制使用最新的SDK去執行
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
節錄.csproj內容
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App"/>
build CI script 如下 (已刪除敏感公司資料?)
編譯:
stage: 建立
image: microsoft/dotnet:2.2-sdk
script:
- dotnet --info
- dotnet restore -r rhel.7-x64 -s $NEXUS_SERVER
- dotnet publish --no-restore -f netcoreapp2.2 -c Release -r rhel.7-x64
cache:
key: build-cache
paths:
- bin
#會把裡面編譯或程式的產出物存放起來,提供介面給其他需要的人使用
artifacts:
paths:
- ./bin/Release/netcoreapp2.2/rhel.7-x64/publish/
全站熱搜
留言列表