首页 > 解决方案 > .NET Core 全局到和自包含 exe

问题描述

我正在创建一个我想要作为“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

解决方案


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


推荐阅读