如何为独立的跨平台 .NET Core 应用程序指定目标运行时?
How to specify the target runtimes for a self-contained cross-platform .NET Core app?
我有一个 .NET Core 控制台应用程序,并希望使其成为面向 Windows 和 Mac OS X.
的独立应用程序
根据我正在学习的教程,方法是编辑项目文件。
为了使其成为独立的 Windows 应用程序,我添加了这一行。
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
这按预期工作,我可以发布应用程序并且一切正常。现在,根据教程,要将 Mac OS X 和 Windows 作为目标,您需要像这样更改该行。
<RuntimeIdentifiers>win10-x64;osx.10.12-x64</RuntimeIdentifiers>
但是,当我将其放入并尝试将更改保存到项目文件时,我 运行 出现以下错误。
与调试文件夹相关:
The "HasTrailingSlash" function only accepts a scalar value, but its
argument "$(OutputPath)" evaluates to
"bin\Debug\netcoreapp2.0\win10-x64;osx.10.12-x64\" which is not a
scalar value. C:\Program Files (x86)\Microsoft Visual
Studio17\Professional\MSBuild.0\Bin\Microsoft.Common.CurrentVersion.targets
与发布文件夹相关:
The "HasTrailingSlash" function only accepts a scalar value, but its
argument "$(OutputPath)" evaluates to
"bin\Release\netcoreapp2.0\win10-x64;osx.10.12-x64\" which is not a
scalar value. C:\Program Files (x86)\Microsoft Visual
Studio17\Professional\MSBuild.0\Bin\Microsoft.Common.CurrentVersion.targets
项目文件仍然保存,一旦我摆脱了所有的警告。他们出现了好几次。具体而言,4 个关于调试路径的警告和 2 个关于发布路径的警告(保存尝试次数?)。
当我关闭解决方案然后再次打开它时,这个特定项目拒绝加载。它只是作为未加载的项目位于解决方案资源管理器中。
如果我尝试重新加载它,我会看到一个漂亮的小红色严重错误图标以及相同的消息。
为什么会这样,似乎是什么问题?请告知,在 Windows 机器上同时针对 Windows 和 Mac OS X 进行独立部署的合适方法是什么?
编辑项目文件仍然是一种有效的方法吗?我关注的教程由 "software architect and developer with a passion for the cloud" 于 2017 年 8 月发布。他确实评论了他编辑项目文件的方法,调用当前工具 "wonky".
更新
<RuntimeIdentifiers>win10-x64;osx.10.12-x64</RuntimeIdentifiers>
这是不是我输入的内容。
相反,这就是我的代码中的内容。注意单数形式。
<RuntimeIdentifier>win10-x64;osx.10.12-x64</RuntimeIdentifier>
问题是我没有注意,也没有手动输入。我使用了代码自动完成 (IntelliSense) 并通过这些标签进行了标记。
一个 RID
对于只有一个运行时标识符 (RID),您可以使用 XML 运行时标识符标记的单数或复数形式。
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
或
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
多个 RID
对于多个 RID,您必须使用 XML 运行时标识符标记的复数形式。
<RuntimeIdentifiers>win10-x64;osx.10.12-x64</RuntimeIdentifiers>
我有一个 .NET Core 控制台应用程序,并希望使其成为面向 Windows 和 Mac OS X.
的独立应用程序根据我正在学习的教程,方法是编辑项目文件。
为了使其成为独立的 Windows 应用程序,我添加了这一行。
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
这按预期工作,我可以发布应用程序并且一切正常。现在,根据教程,要将 Mac OS X 和 Windows 作为目标,您需要像这样更改该行。
<RuntimeIdentifiers>win10-x64;osx.10.12-x64</RuntimeIdentifiers>
但是,当我将其放入并尝试将更改保存到项目文件时,我 运行 出现以下错误。
与调试文件夹相关:
The "HasTrailingSlash" function only accepts a scalar value, but its argument "$(OutputPath)" evaluates to "bin\Debug\netcoreapp2.0\win10-x64;osx.10.12-x64\" which is not a scalar value. C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.0\Bin\Microsoft.Common.CurrentVersion.targets
与发布文件夹相关:
The "HasTrailingSlash" function only accepts a scalar value, but its argument "$(OutputPath)" evaluates to "bin\Release\netcoreapp2.0\win10-x64;osx.10.12-x64\" which is not a scalar value. C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.0\Bin\Microsoft.Common.CurrentVersion.targets
项目文件仍然保存,一旦我摆脱了所有的警告。他们出现了好几次。具体而言,4 个关于调试路径的警告和 2 个关于发布路径的警告(保存尝试次数?)。
当我关闭解决方案然后再次打开它时,这个特定项目拒绝加载。它只是作为未加载的项目位于解决方案资源管理器中。
如果我尝试重新加载它,我会看到一个漂亮的小红色严重错误图标以及相同的消息。
为什么会这样,似乎是什么问题?请告知,在 Windows 机器上同时针对 Windows 和 Mac OS X 进行独立部署的合适方法是什么?
编辑项目文件仍然是一种有效的方法吗?我关注的教程由 "software architect and developer with a passion for the cloud" 于 2017 年 8 月发布。他确实评论了他编辑项目文件的方法,调用当前工具 "wonky".
更新
<RuntimeIdentifiers>win10-x64;osx.10.12-x64</RuntimeIdentifiers>
这是不是我输入的内容。
相反,这就是我的代码中的内容。注意单数形式。
<RuntimeIdentifier>win10-x64;osx.10.12-x64</RuntimeIdentifier>
问题是我没有注意,也没有手动输入。我使用了代码自动完成 (IntelliSense) 并通过这些标签进行了标记。
一个 RID
对于只有一个运行时标识符 (RID),您可以使用 XML 运行时标识符标记的单数或复数形式。
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
或
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
多个 RID
对于多个 RID,您必须使用 XML 运行时标识符标记的复数形式。
<RuntimeIdentifiers>win10-x64;osx.10.12-x64</RuntimeIdentifiers>