C#C
C#2y ago
Byron

Nuget Package: Project Reference Mutli Runtime Targeting

Hey Folks,

I have a nuget package that wraps an exe, which I need to run on both linux and windows. I was trying to set it up so when I build my nuget package it compiles the other project reference and generates two executables. Altought what I have works it seems a bit hacky. I was wondering if there was a cleaner way of going about this


ini 
App.Tool: Dotnet cli tool 
App.MSBuild: References App.Tool and should build it twice and be contained within the nuget package. 


<!--==== App.MSBuild =====-->

<!-- Include in generated Nuget Package -->
<Target Name="AddNugetContent">
  <ItemGroup>
    <TfmSpecificPackageFile Include="$(PublishDir)$(LinuxRuntime)\*.*">
      <PackagePath>tool/bin/$(LinuxRuntime)/%(RecursiveDir)</PackagePath>
    </TfmSpecificPackageFile>
    <TfmSpecificPackageFile Include="$(PublishDir)$(WindowsRuntime)\*.*">
      <PackagePath>tool/bin/$(WindowsRuntime)/%(RecursiveDir)</PackagePath>
    </TfmSpecificPackageFile>
  </ItemGroup>
</Target>
<!-- Double Publish -->
<Target Name="MultiRuntimeBuild" BeforeTargets="Build">
  <Message Importance="high" Text="BaseOutputPath: $(BaseOutputPath)"/>
  <MSBuild Projects="$(ToolProjectDirectory)App.Tool.csproj" Targets="Publish" Properties="RuntimeIdentifier=$(LinuxRuntime);SelfContained=true;TargetFramework=net6.0;PublishDir=$(PublishDir)$(LinuxRuntime)" />
  <MSBuild Projects="$(ToolProjectDirectory)App.Tool.csproj" Targets="Publish" Properties="RuntimeIdentifier=$(WindowsRuntime);SelfContained=true;TargetFramework=net6.0;PublishDir=$(PublishDir)$(WindowsRuntime)"  />
</Target>
Was this page helpful?