Although the question is vague about what you want and don't want, together with the comments I think I have an idea now:
- You want to distribute an application (exe and accompanying files) via a nuget package.
- You want to consume that nuget package in a project.
- You want to execute the application from that package at runtime from the project's code.
- You do not want to have the application files lying around in the project's output folder.
You already did 1. by adding the application to the package as content.
You also already did 2.
To accomplish 3. you have to be able to access the application file at runtime from a known permanent location. The "package" is a build-time concept. It does not exist at runtime.
During the build (package restore), nuget will download the package and then store it and its contents in a local package cache folder.
From your question in the comments above I understand your plan was to have your project execute the exe in that folder.
That is possible, but highly inadvisable. You cannot rely on the local package cache folder. It is a cache. It can be deleted at any time.
What you can do instead is what Fidor hinted at: add the application files as embedded resource to your project assembly. This will bloat your project's assembly but makes all application files available at runtime without them lying around somewhere.
You do not need ILMerge for that though, because you control the project assembly build.
Creating and using embedded resources from a nuget package
To do that you have to add the application files to the EmbeddedResource
item in your project.
For that you need the build-time location of the nuget package contents.
You get the latter by adding GeneratePathProperty="true"
to your PackageReference
.
This gives you an MSBuild property called Pkg<your_package_name_sanitized
containing the root path of the nuget package contents (see the docs).
You can then use that variable to declare a globbed path to the application files within the package, like so:
<PackageReference Include="My.Package" Version="1.0.0" GeneratePathProperty="true" />
<EmbeddedResource Include="$(PkgMy_Package)/contentFiles/any/netstandard2.0/**/*" LinkBase="App" />
This will make all application files available at runtime as embedded resources with the name prefix <project_assembly_root_namespace>.App.
.
You then get a stream for an embedded file at runtime with
typeof(SomeProjectType).Assembly.GetManifestResourceStream("Project.Root.Namespace.App.MyApplication.exe")
and can e. g. save the files to a location from which they can be executed as their own process.