【问题标题】:.NET Core Global To and Self Contained exe.NET Core 全局到和自包含 exe
【发布时间】:2019-09-01 09:33:06
【问题描述】:

我正在创建一个我想要作为“dotnetcore 全局工具”和独立 exe 的 exe。这是我的 csproj 的样子:

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <LangVersion>7.1</LangVersion>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
    <PackAsTool>true</PackAsTool>
    <IsPackable>true</IsPackable>
    <ToolCommandName>HostRunner</ToolCommandName>
    <PackageOutputPath>./nupkg</PackageOutputPath>
    <AssemblyName>HostRunner</AssemblyName>
  </PropertyGroup>

我可以运行dotnet pack没问题,但是当我运行时

dotnet publish my.csproj -r=win10-x64 -c=Debug --self-contained

我收到一条错误消息error NETSDK1053: Pack as tool does not support self contained.

我做错了什么?!

【问题讨论】:

    标签: c# command-line-interface .net-core-2.2


    【解决方案1】:

    你需要两个 csprojs。一个用于 nuget 包,一个用于 exe。让exe一个使用nuget包一个。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。 我正在使用这样定义的单独属性组:

      <PropertyGroup Condition="$(TargetFramework) != 'net462'">
          <PackAsTool>true</PackAsTool>
          <ToolCommandName>my-command</ToolCommandName>
          <PackageOutputPath>./nupkg</PackageOutputPath>
      </PropertyGroup>
      

      【讨论】:

      • 你能解释一下 "$(RuntimeIdentifier) == ''" 的作用吗?
      【解决方案3】:

      同样的问题,找到了reply on GitHub

      刚刚删除了指令

      <PackAsTool>true</PackAsTool>
      

      在 .csproj 文件中,它就像以前一样工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-21
        • 1970-01-01
        • 1970-01-01
        • 2020-09-10
        • 2020-02-01
        相关资源
        最近更新 更多