.NET Core全局收件人和自包含的exe

时间:2019-04-10 20:22:57

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

我正在创建一个我想拥有的exe文件,作为“ dotnetcore全局工具”以及独立的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.

我在做什么错?!

3 个答案:

答案 0 :(得分:1)

您需要两个csprojs。一个用于nuget软件包,另一个用于exe。使exe一个使用nuget包一个。

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

这里是同一问题,找到了replay on GitHub

只是删除了指令

<PackAsTool>true</PackAsTool>

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

相关问题