oleg-shilo / wixsharp

Framework for building a complete MSI or WiX source code by using script files written with C# syntax.
MIT License
1.12k stars 175 forks source link

Trying to copy created .msi to an another location depending on ${ConfigurationType} #1626

Closed exedor closed 2 months ago

exedor commented 2 months ago

When I build my project (Debug or Release) it creates a single file in \.msi

I need to automate copying debug and release builds of the installation to each of their respective locations. I learned this happens at runtime, not compile time and the build process in the project does some tasks at run time. So, I added this at the bottom of the Main function:

            project.BuildMsi();

            // Copy the compiled and built MSI into the appropriate folder
            System.IO.File.Move(FinalMSISourceFile, FinalMSIDestFile);

It produces this error: Severity Code Description Project File Line Suppression State Details Error (active) MSB3073 The command "cd .\ set ide=true "C:\source\repos\Solution1\WixSharpInstall\bin\Debug\net472\WixSharpInstall.exe"" exited with code -532462766. WixSharpInstall C:\source\repos\Solution1\WixSharpInstall\WixSharpInstall.csproj 30

So the build fails with this error message. What is the recommended way to take the default .msi file created in the project directory and copy it to another directory with a different filename after it's creation? I've already learned enough to know that the post-build event in the Visual Studio project isn't a good solution. I've also noticed the "publish" action just places all the files that get bundled into the msi into that location, not the msi itself. So all the normal ways I know of doing something like this, it seems, are not an option.

exedor commented 2 months ago

Never mind. I figured it out. I am not entirely sure why, but the Visual Studio build process seems to create and delete the msi file twice. The first time creates the copy of the destination file. The second time, it already exists so the copy command fails. So the above code works fine if it includes this:

            project.BuildMsi();

            // Copy the compiled and built MSI into the appropriate folder
            if (System.IO.File.Exists(FinalMSIDestFile))
                System.IO.File.Delete(FinalMSIDestFile);
            System.IO.File.Copy(FinalMSISourceFile, FinalMSIDestFile);