我正在使用.NET Core应用程序和自包含的发布搜索错误消息和不清楚的行为。我刚安装了.NET Core 2.2.3 SDK并使用Visual Studio 2017(15.9)创建了一个名为CoreVerTest
的简单控制台应用程序。到目前为止一切都还可以。它说“Hello World!”当我运行它。
然后我继续创建自包含版本的构建脚本。这是项目目录中的脚本build.cmd
(其中.csproj是):
@echo off
set TargetFramework=netcoreapp2.2
:: Clean
if exist bin\Release\%TargetFramework% rd /s /q bin\Release\%TargetFramework% || goto error
dotnet clean -v m -c Release -nologo || goto error
:: Build
powershell write-host -fore Blue Building and publishing...
dotnet publish -c Release -nologo || goto error
powershell write-host -fore Blue Publishing for win-x64...
dotnet publish -c Release -r win-x64 -nologo || goto error
powershell write-host -fore Blue Publishing for linux-arm...
dotnet publish -c Release -r linux-arm -nologo || goto error
:: Exit
powershell write-host -fore Green Build finished.
timeout /t 2 /nobreak >nul
exit /b
:error
pause
这清理了一切,然后做了
我根本没有碰过.csproj文件,这都是默认值。
这有很多问题:
如何摆脱Visual Studio中的错误消息并验证所有版本是否正确(期望依赖于框架的应用程序以2.2.0为目标并在安装时运行2.2.3;期望自包含应用程序包含位仅2.2.3)?
(我已经在其他地方报告了错误消息,但无法找到它的位置。也没有解决方案。)
编辑以处理这两种情况。
尝试使用RuntimeIdentifier上的条件设置RuntimeFrameworkVersion:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'win-x64'">
<RuntimeFrameworkVersion>2.2.2</RuntimeFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'linux-arm'">
<RuntimeFrameworkVersion>2.2.2</RuntimeFrameworkVersion>
</PropertyGroup>
</Project>
注意:上面我将RuntimeFrameworkVersion设置为2.2.2只是为了验证自包含的发布不仅仅是获取我系统上安装的最新版本。您可以将其设置为所需的版本。
构建之后,您应该看到: