0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

dotnet publishをするとエラーMSB4126が発生する

Posted at

riderで作成したapiをdotnetコマンドでpublishした際にエラーでハマったのでメモ

結論

dotnet publish -p:Configuration=Release -p:Platform="Any CPU"

環境

macOs Catalina 10.15.7
Rider 2020.03.2
docnet core 5.0.103

問題

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ./*.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet build -c Release -o /app

FROM build AS publish
RUN dotnet publish -c Realease -o /app

FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT [ "dotnet", "hoge.dll"]

こちらを実行すると掲題のエラーが発生。

  • 上記はdockerfileだが、結局ローカルで試しても発生したため、dockerのせいではなかった。

エラー内容

error MSB4126: The specified solution configuration "Realese|Any CPU" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration. 

hoge.sln


Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hoge", "hoge.csproj", "{F5EA8D2E-2117-4753-93CB-EF809C3A7D1B}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{F5EA8D2E-2117-4753-93CB-EF809C3A7D1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{F5EA8D2E-2117-4753-93CB-EF809C3A7D1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{F5EA8D2E-2117-4753-93CB-EF809C3A7D1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{F5EA8D2E-2117-4753-93CB-EF809C3A7D1B}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
EndGlobal

ソリューションファイルをみても特に問題点が見当たらない。

調査と唐突な解決

調査してみたが、visual Stadioでソリューションファイルのプロパティを云々、というのが多かった。
が、当然Riderでは使えそうにない。

こちらを見ると、Any CPUというパラメータを追加しろとのこと。
しかし、VSではないので追加の仕方がわからない。。。

ふと、 /p:Configuration=Debug /p:Platform="Any CPU" こちらの一文が気になって、追加して実行してみた。

dotnet publish -p:Configuration=Release -p:Platform="Any CPU"

動いた。
https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish
しかし、こちらにもこのオプションについての記載がなく、仔細はなぞのまま。
とりあえず動いたのでよし。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?