How to package windows specific executable in nupkg with Net Core 8 SDK style project

20 hours ago 1
ARTICLE AD BOX

I have two .NET 8 WinExe projects; MyBuildTool and MyRuntimeTool

MyBuildTool.csproj (MyRunTimeTool.csproj is similar)

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0-windows</TargetFramework> <Platforms>x64</Platforms> <OutputType>WinExe</OutputType> </PropertyGroup> <ItemGroup> <PackageReference Include="Newtonsoft.Json" Version="13.0.4" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\MyLibrary\MyLibrary.csproj" /> </ItemGroup> </Project>

In another project MyCustomerProject, I would like to do two things:

Use MyBuildTool.exe as a post build step in order to generate some metadata needed for a company process. "run" MyCustomerProject with MyRuntimeTool.exe. (Ie. MyCustomerProject is actually a "plugin" for the MyRuntimeTool framework). Eg. publish the complete output of MyRuntimeTool and MyCustomerProject as a single package

MyCustomerProject.csproj

<?xml version="1.0" encoding="utf-8"?> <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Library</OutputType> <TargetFramework>net8.0-windows</TargetFramework> <Platforms>x64</Platforms> </PropertyGroup> <PackageReference Include="MyCompany.MyBuildTool" Version="1.0.0" /> <PackageReference Include="MyCompany.MyRuntimeTool" Version="1.0.0"/> <PackageReference Include="System.Drawing.Common" Version="10.0.3" /> </ItemGroup> <PropertyGroup> <PostBuildEvent>"$(TargetDir)MyBuildTool.exe" "$(TargetDir)someConfig.json" "SomeOutPutDir"</PostBuildEvent> </PropertyGroup> </Project>

This was previously managed with a lot of custom "copy dlls around" scripting, but I'd really like to manage this with nupkg distribution to simplify a lot of company processes.

Unfortunately as written this doesn't work:

MyBuildTool.dll is copied into the output folder for MyCustomerProject, but the exe isn't. MyCustomerProject also ends up linking against MyLibrary and everything else that MyBuildTool.dll depends on, which isn't ideal. Preferably any dependency of MyBuildTool would be available so the exe can run, but not transitively linked in the MyCustomerProject assembly

I have tried:

Package MyBuildTool as a "dotnet tool" - this doesn't work because dotnet tools don't support windows specific target frameworks or WPF (which is used by MyLibrary unfortunately) Add the MyBuildTool.exe as a "content file" in the MyBuildTool.csproj - I can't get this to copy into MyCustomerProject output directory - this also seems very fragile but I'm willing to manually copy every dll if I can figure out how to get them all in the right place

All of the resources I have been able to google are NET Framework or .nuspec specific, but from what I understand the guidance for Net Core 8+ projects is to generate the nuspec entirely from the .csproj file so I'd like to do that if possible.

Read Entire Article