【问题标题】:Reinforced.Typings can't find dotnet.exe on MacOSReinforced.Typings 在 MacOS 上找不到 dotnet.exe
【发布时间】:2021-09-08 17:57:56
【问题描述】:

我正在 MacOS 和 Reinforced 上开发 dotnet 5 解决方案。Typings 给了我以下编译错误。它正在尝试运行 dotnet.exe,我怀疑这是问题的核心,因为它在 MacOS 上不存在。关于如何修复它的任何线索?

/Users/myuser/.nuget/packages/reinforced.typings/1.6.1/build/Reinforced.Typings.targets(3,3): Error MSB6003: The specified task executable "" could not be run. System.ComponentModel.Win32Exception (0x80004005): ApplicationName='dotnet.exe', CommandLine=' "/Users/myuser/.nuget/packages/reinforced.typings/1.6.1/tools/net5.0/rtcli.dll" profile "/var/folders/q3/zth_hlj12ts4w6zc9m42_ctr0000gn/T/tmp316575ae.tmp"', CurrentDirectory='', Native error= Cannot find the specified file
  at System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) [0x0029f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/System/System.Diagnostics/Process.cs:778 
  at System.Diagnostics.Process.Start () [0x0003a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/services/monitoring/system/diagnosticts/Process.cs:2006 
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
  at Microsoft.Build.Utilities.ToolTask.ExecuteTool (System.String pathToTool, System.String responseFileCommands, System.String commandLineCommands) [0x000c9] in /Users/builder/jenkins/workspace/build-package-osx-mono-pullrequest/pr/external/bockbuild/builds/msbuild-15/src/Utilities/ToolTask.cs:711 
  at Microsoft.Build.Utilities.ToolTask.Execute () [0x00433] in /Users/builder/jenkins/workspace/build-package-osx-mono-pullrequest/pr/external/bockbuild/builds/msbuild-15/src/Utilities/ToolTask.cs:1519  (MSB6003) (MyProject.Core)

我的配置类如下所示:

namespace MyProject.Core
{
    public static class ReinforcedTypingsConfiguration
    {
        public static void Configure(ConfigurationBuilder builder)
        {
            builder.Global(x => x.ExportPureTypings()
                                 .CamelCaseForProperties()
                                 .AutoOptionalProperties(true));

            builder.ExportAsInterfaces(TypesToExport);
        }

        private static List<Type> TypesToExport = new()
        {
            typeof(ProductDto)
        };
    }
}

我的 Reinforced.Typings.settings.xml 看起来像这样:

<?xml version="1.0" encoding="UTF-8" ?>
<Project>
  <PropertyGroup>
    <RtForceTargetFramework>net5.0</RtForceTargetFramework>
    <RtTargetFile>$(ProjectDir)/contracts.d.ts</RtTargetFile>
    <RtConfigurationMethod>MyProject.Core.ReinforcedTypingsConfiguration.Configure</RtConfigurationMethod>
    <RtDivideTypesAmongFiles>false</RtDivideTypesAmongFiles>
    <RtBypassTypeScriptCompilation>false</RtBypassTypeScriptCompilation>
    <RtDisable>false</RtDisable>
  </PropertyGroup>
</Project>

【问题讨论】:

标签: c# macos .net-core reinforced-typings


【解决方案1】:

检查 Reinforced.Typings 的源代码,它内部调用RuntimeInformation.IsOSPlatform(OSPlatform.Windows) 来确定是使用"dotnet.exe" 还是"dotnet"。

尝试创建一个简单的控制台应用程序并检查RuntimeInformation.IsOSPlatform(OSPlatform.Windows) 返回的内容。

源码:RtCli.cs

【讨论】:

  • 正如预期的那样,OSPlatform.OSX 将返回 True,False 将返回 False。如果您指的是包含在#if NETCORE 预处理器指令中,我猜这会使代码默认为dotnet.exe。有趣的是,完全相同的代码在 Rider 上编译和工作正常,但不适用于 Mac 的 Visual Studio Community 版本,所以我猜他们在某处传递了不同的参数。
【解决方案2】:

Reinforced.Typings 通过运行dotnet build *.sln 在命令行中按预期工作。它也适用于包含相同构建命令的 Rider。

从 Visual Studio for Mac 构建是另一回事。它似乎在构建时运行了很多东西,但不是dotnet build。不完全确定 Visual Studio for Mac 正在运行什么命令,但它看起来像是某种与目标/任务相关的流,它以某种方式将 OsPlatform 设置为 OsPlatform.Windows,即使它显然不正确。

【讨论】:

    【解决方案3】:

    我 10 个月前问过同样的问题,但仍然没有答案。我的猜测是构建 nuget 包时未定义 NETCORE。

    Reinforced.Typings is looking for dotnet.exe on MacOS so it can't run

    【讨论】:

      猜你喜欢
      • 2020-10-03
      • 2017-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 2021-08-17
      • 2021-04-16
      • 2019-01-25
      相关资源
      最近更新 更多