2

I have added a build EXE tool in the tools folder of my nuspec, and it is correctly added to the target application under \packages\xxx\tools folder.

But I need to invoke this file as a Build Action in the target project. What's the correct way to reference it? Bear in mind that with every new version of the package, the folder name inside \packages\ will be changed. So I cannot hardcode that.

Paymon
  • 1,173
  • 1
  • 9
  • 26
  • 1
    Did you ever find an answer to this? – Devedse Jul 24 '17 at 22:40
  • "I need to invoke this file as a Build Action": Do you mean a pre-build/post-build step? If you need to set the Build Action on a file, you can manually specify it. See the [documentation](https://learn.microsoft.com/en-us/nuget/schema/nuspec#including-content-files) and search for "buildAction". – techvice Dec 08 '17 at 19:27
  • @techvice, I did have the post-build step, but the problem was dispatching the updated EXE file through Nuget just as any other package update is delivered. – Paymon Mar 12 '18 at 08:40
  • @Devedse, I posted my solution as an answer. – Paymon Mar 12 '18 at 08:53

1 Answers1

0

In my case, I had this situation:

  • The target project was a .NET Core app.
  • The EXE file was not .NET Core and had to remain EXE

I invented a workaround:

  1. Created a console app DLL project (.NET core) and added the EXE file as Embedded Resource inside it.
  2. Created a normal NuGet package for the new DLL file.
  3. In the target apps, I referenced this package (dll), so all future versions get updated in the normal NuGet way.
  4. In the target app I added a post-build event to run the dll file:

    dotnet TheDllName.dll

    Packaged the DLL file in the normal way and referenced in the target app. In the which is dispatched in the normal way. Every time the NuGet package is updated, the new EXE will be also distributed inside the DLL. Then I used a command

What happens when the DLL runs?

  1. Reads the EXE file from itself, like any other embedded resource.
  2. Saves it on the disk as EXE file.
  3. Starts a new process to run the EXE file.

Optimization

This is not absolutely necessary, but to optimize the above process, I also added a version file (simple txt file named ver.txt) to record the version number of the EXE file, so I only extract and save it once per updated NuGet package.

Paymon
  • 1,173
  • 1
  • 9
  • 26