How to consume a dotnet console application from a Nuget package?

时间:2018-01-23 19:34:58

标签: c# .net nuget .net-core

The scenario is as follows:

a) An arbitrary MyProject.csproj invokes MyConsoleApp.exe as part of a post build event.

b) MyConsoleApp.exe is packaged and consumed via Nuget with all its dependencies

I am not convinced this is the "dotnet core 2.0" way of doing things, I tried dotnet pack MyConsoleApp.csproj but that doesn't include the dependencies like the .exe file does. Should it include all references in a nupkg and publish the package at build time?

MyProject.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  ...
  <Target Name="GenerateSomeFiles" BeforeTargets="AfterBuild">
    <Exec Command="dotnet run MyConsoleApp.dll $(TargetDir)" />
  </Target>
</Project>

1 个答案:

答案 0 :(得分:0)

您应该尝试运行dotnet发布,然后针对在bin / Release或bin / Debug下创建的发布文件夹运行dotnet pack。

如果您仍然想要一个exe,您应该在csproj中为x86 / x64设置目标Runtime,或者为完整框架版本设置多目标。