Launch NSIS when building with Visual Studio - visual-studio-2010

I have written a NSIS script for my project, and I would like to automatically create the setup file when I build the project. How can I do this with Visual Studio? Is there a way to pass parameters to the script?
I mean, I would like VS to pass the Assembly Version to the script. Right now, I have to manually edit a line in the script
VIProductVersion 1.5.0.1
and I sometime forget to update it. Is there a way to automate the process?

You can create defines and/or execute script instructions by using the /D and /X makensis parameters
NSIS can also read files with !searchparse

There are two questions here.
Q1. Launch NSIS when building with Visual Studio?
A1. Make a Post-build event that runs makensis on the .nsi file:
"C:\Program Files (x86)\NSIS\makensis.exe" "$(ProjectDir)\NSISInstaller\Installer.nsi"
Q2. Pass the Assembly Version to the post build event?
A2. Answered here: Determine assembly version during a post-build event
Combined solution should be:
"C:\Program Files (x86)\NSIS\makensis.exe" "$(ProjectDir)\NSISInstaller\Installer.nsi" /DPRODUCT_VERSION=$(AssemblyVersion)

Related

CMake run shell command after building error

I have a Visual Studio 2019 CMake project and i need to run a postbuild script which copys a file (The file is not generated by the build process). What i did so far is add a custom command in CMake with
add_custom_command(TARGET testExec POST_BUILD COMMAND "../postbuild.bat")
The postbuild.bat would copy the file. This works great most of the time but when my build fails due to some compile error, the postbuild script won't be executed.
How can i run the postbuild script even if the build fails ? I know there is a similar question here but sadly no proper solution. If there is a way to configure a postbuild event directly inside a Visual Studio CMake project this would also be suitable, but it seems like this is not possible (because in a cmake project i don't have a project file).
Since The copied file is not generated by the build you can use PRE_BUILD. On Visual Studio Generators, it runs before any other rules are executed within the target.(https://cmake.org/cmake/help/latest/command/add_custom_command.html).
The other solution could be to use add_custom_command(OUTPUT as the file seems independent of the build.

Run executable from linked file in visual studio post build command line

I have a windows service executable in a separate visual studio project that I would like to start running during the post build event on a web forms project. I have added the executable to my web project as a linked file. I am trying to run a start command to boot up the windows service in the post build events command line, but I can't figure out how to get the file path of the executable from the linked file. Is this possible?
I ended up retrieving the file path from a powershell script and placing it in a custom macro to hold the file path in the .csproj file. I just run the powershell script pre build and the exe post build using the build events command line. A terrible hack, to be revisited another time.

Visual Studio TypeScript post-compile-on-save event

I have a TypeScript project with 'compile on save' option enabled.
I would like to execute external command (executable file) after every time I save a file in my TypeScript project.
How to do it?
Compile on save is specific to typescript and not available as a build step. You can do that using external tools e.g combine https://github.com/gruntjs/grunt-contrib-watch and https://github.com/grunt-ts/grunt-ts
There is a sample extension for Visual Commander that runs cppcheck on file save (#2) using DTE.Events.DocumentEvents.DocumentSaved. You can easily adapt it to run your executable instead.

Is there a way to separately get the Program Files output for Visual Studio setup projects?

In a Visual Studio setup project, you define a Program Files output (amongst other things of course).
Is there any way to output this to a folder directly, i.e. get that output without actually building and installing the msi to Windows?
What I am looking for is something similar to the "File System" publish method for web projects.
Alternatively, I could do with a "portable install" option in the msi (similar for instance to the Firefox portable install), or an switch in msiexec (I did not find anything like this in the documentation), or a way to extract this folder structure from the msi via a third-party tool.
Take a look at Administrative Installation. You run a postbuild command like:
msiexec /a "$(TargetPath)" /qn TARGETDIR="$(OutDir)\Extract"
Please note that I didn't test that command but that's the general concept. This will extract your MSI to a directory.

Batch Builds in Visual Studio 6 for VC++ project

In VS 2008 and VS 2010, one can easily create a solution and modify the "Solution Configuration". We can choose what configuration each project gets built in when we trigger a build at the solution level.
Is such a facility available in the Visual Studio 6.0?
In my experience:
when a configuration is chosen (form the list available) in VS6 for a VC++ project, the dependencies (which themselves have multiple configurations defined) get built in some random order. There is no way to control the configurations of dependencies at build time.
"Batch Build" does come close to this but is not as flexible for my purpose.
I have tried various options in the VS6.
Hope I am clear.
Here is a link on the MSDEV command line.
https://msdn.microsoft.com/en-us/library/aa699274(v=vs.60).aspx
There is a way to control the building of dependencies. Specify /NORECURSE and dependencies will not be built.
I use /REBUILD with /NORECURSE to keep the dependencies from getting built.
And I build each project one at a time inside the workspace in a bat file by doing a chdir to the subdirectory and calling MSDEV just for that subproject:
msdev myproject.dsp /MAKE "myproject - Win32 Debug" /REBUILD /NORECURSE > Build.log
Then I cd to the next project directory one at a time.
On a side note, I had difficulties for several years where NMAKE would not work for my specific tasks. Turns out that the PATH environment variable inside MSDEV (Visual Studio 6.0) is different from the PATH environment variable of a command shell you would run NMAKE on.
The Path used by the MSDEV shell is the %PATH% at the time Visual Studio 6 was installed. We use this and poke the registry as needed for MSDEV to get the correct path setup when switching revisions of our software; however this doesn't help update the %PATH%. The MSDEV path can be queried with a query script. I don't have my example handy.
That is why builds in MSDEV sometimes work when builds using the command line don't, as the path to DLLs differ, and any custom build steps that run .exe will not work outside of the MSDEV environment unless the path is updated.
I have a script somewhere that reads the queries the registry to extract the MSDEV path and update PATH of a shell so that batch scripts doing nmake will work as they would inside the MSDEV shell environment. The problem with the REGISTRY QUERY is that the return arguments differ with different flavors of Windows (XP/SERVER2003/...).
One thing I just discovered is that Incredibuild works with the old VS6.0 MSDEV IDE. This is a game changer. It distributes builds. I'm evaluating it now, but it might be useful to anyone waiting for long VS6.0 builds.

Resources