3

I have a solution in Visual Studio 2013 with many different projects. One of them is C# screensaver, built as Windows Application (file extension ".exe"). Now i want that screensaver to be packed into a visual studio setup project. But in the setup project i can only include the "primary output" of the C# project so that the output file is packed unchanged into the msi file. Is there a way to change the file extension (it has to be .scr) either in the C# project settings or in the Setup itself? When i change the filename via batch/MSBuild order in the postbuild event the "primary output" for the setup cant be found anymore. The strange thing is: there is already an option in the setup that says "TargetName", but it is greyed and i cant change it in the IDE and i also cant find the option in the project file of the setup project. Thanks for any help!

Edit 1:

Is it possible that there is abolutely NO solution for simply renaming an output file to include it in a setup??

Sascha
  • 65
  • 7
  • possible duplicate of [Rename project output before being included into Setup project](http://stackoverflow.com/questions/2420611/rename-project-output-before-being-included-into-setup-project) – DavidG Jun 26 '14 at 12:42
  • 1
    I tried adding the Copy order within the AfterBuild event but the setup project still takes the ".exe" file. It seems that doesnt take effect on the "primary output". – Sascha Jun 26 '14 at 12:55
  • Do all the executables end up in the same directory or in different directories? – cup Jun 27 '14 at 07:50
  • its different depending on the project type. The C# outputs are createt in their own bin folder in the project directory and the C++ projects end up in the common "Release" folder of the solution. But in the setup i only give a reference to the projects so it looks for the outputs itself. – Sascha Jun 27 '14 at 08:05
  • Even in VS2019, adding `ScreenSaver.scr` manually to the csproj results in a generated assembly of `ScreenSaver.scr.dll` – ClickRick May 15 '21 at 15:57

1 Answers1

2

Since I found absolutely no solution to configure my Setup for renaming the file i finally created an additional DLL with an InstallerClass to run it as Custom Action during the install process.

Here is a good sample how to do that for anyone who has similar problems

Custom Action in Visual Studio setup projects (Code Project)

I simply renamed the file in the Install method and renamed it back in the Uninstall method so it gets deleted properly.

    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
        var text = Context.Parameters["ScreensaverPath"];
        var file = new FileInfo(text + "MyScreenSaver.exe");
        if (!file.Exists)
            return;
        file.MoveTo(text + "MyScreenSaver.scr");
    }

    public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);
        var text = Context.Parameters["ScreensaverPath"];
        var file = new FileInfo(text + "MyScreenSaver.scr");
        if (!file.Exists)
            return;
        file.MoveTo(text + "MyScreenSaver.exe");
    }
Sascha
  • 65
  • 7