简体   繁体   English

如何为独立的跨平台.NET Core应用程序指定目标运行时?

[英]How to specify the target runtimes for a self-contained cross-platform .NET Core app?

I have a .NET Core console app and want to make it a self-contained app that targets Windows and Mac OS X. 我有一个.NET Core控制台应用程序,想要使其成为针对Windows和Mac OS X的独立应用程序。

The way to do it, according to a tutorial that I'm following, is to edit the project file. 根据我所遵循的教程,执行此操作的方法是编辑项目文件。

To make it a self-contained Windows only app, I add this line. 为了使其成为一个独立的Windows应用程序,我添加了这一行。

<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>

This works as expected, and I can publish the app and everything works. 这可以按预期工作,我可以发布该应用,一切正常。 Now, to target Mac OS X as well as Windows, according to the tutorial, you need to change that line like this. 现在,根据教程,要同时针对Mac OS X和Windows,您需要像这样更改该行。

<RuntimeIdentifiers>win10-x64;osx.10.12-x64</RuntimeIdentifiers>

However, when I put that in and try to save the changes to the project file, I run into the following error(s). 但是,当我将其放入并尝试将更改保存到项目文件时,遇到以下错误。

Related to Debug folder: 与Debug文件夹有关:

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. “ HasTrailingSlash”函数仅接受标量值,但其参数“ $(OutputPath)”的计算结果为“ bin \\ Debug \\ netcoreapp2.0 \\ win10-x64; osx.10.12-x64 \\”,这不是标量值。 C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\Microsoft.Common.CurrentVersion.targets C:\\ Program Files(x86)\\ Microsoft Visual Studio \\ 2017 \\ Professional \\ MSBuild \\ 15.0 \\ Bin \\ Microsoft.Common.CurrentVersion.targets

Related to Release folder: 与Release文件夹相关:

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. “ HasTrailingSlash”函数仅接受标量值,但其参数“ $(OutputPath)”的计算结果为“ bin \\ Release \\ netcoreapp2.0 \\ win10-x64; osx.10.12-x64 \\”,这不是标量值。 C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\Microsoft.Common.CurrentVersion.targets C:\\ Program Files(x86)\\ Microsoft Visual Studio \\ 2017 \\ Professional \\ MSBuild \\ 15.0 \\ Bin \\ Microsoft.Common.CurrentVersion.targets

The project file is still saved, once I get away from all the warnings. 一旦我摆脱了所有警告,项目文件仍将保存。 They appear several times. 他们出现了几次。 Specifically, 4 warnings about debug path and 2 about release path (number of save attempts?). 具体来说,有4条关于调试路径的警告和2条关于释放路径的警告(保存尝试次数?)。

在此处输入图片说明 在此处输入图片说明

When I close the solution and then open it again, this particular project refuses to load. 当我关闭解决方案然后再次打开它时,该特定项目拒绝加载。 It just sits in Solution Explorer as a project that's not loaded. 它只是作为未加载的项目放在解决方案资源管理器中。

在此处输入图片说明

If I try to reload it I get a nice little red, critical error icon along with the same message. 如果我尝试重新加载它,我会看到一个漂亮的红色严重错误图标以及相同的消息。

在此处输入图片说明

Why is this happening, what seems to be the problem? 为什么会这样,这似乎是什么问题? Please advise, what's the appropriate way to target both Windows and Mac OS X for self-contained deployment on a Windows machine? 请告知,同时针对Windows和Mac OS X在Windows计算机上进行自包含部署的适当方法是什么?

Is editing the project file still a valid approach? 编辑项目文件仍然是有效的方法吗? The tutorial I am following was released in August 2017 by a "software architect and developer with a passion for the cloud". 我关注的教程是由“对云充满热情的软件架构师和开发人员”于2017年8月发布的。 He did comment on his approach of editing the project file, calling the current tooling "wonky". 他确实对编辑项目文件的方法发表了评论,称当前工具“怪异”。

Update 更新资料


<RuntimeIdentifiers>win10-x64;osx.10.12-x64</RuntimeIdentifiers>

This is not what I had typed in. 不是我输入的内容。

Instead, this is what I had in my code. 相反,这就是我在代码中所拥有的。 Notice the singular form. 注意单数形式。

<RuntimeIdentifier>win10-x64;osx.10.12-x64</RuntimeIdentifier>

The problem lies in that I did not pay attention, nor did I type it in manually. 问题在于我没有注意,也没有手动输入。 I used code auto-completion (IntelliSense) and just tabbed through these tags. 我使用了代码自动完成(IntelliSense),并通过这些标签进行了制表。

One RID 一个RID

For only one runtime identifier (RID), you can use either the singular or the plural form of the XML runtime identifier tag. 对于仅一个运行时标识符(RID),可以使用XML运行时标识符标记的单数或复数形式。

<RuntimeIdentifier>win10-x64</RuntimeIdentifier>

OR 要么

<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>

Multiple RIDs 多个RID

For more than one RID, you have to use the plural form of the XML runtime identifier tag. 对于多个RID,您必须使用XML运行时标识符标签的复数形式。

<RuntimeIdentifiers>win10-x64;osx.10.12-x64</RuntimeIdentifiers>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM