Skip to content

Instantly share code, notes, and snippets.

@benhysell
Created March 10, 2015 19:32
Show Gist options
  • Select an option

  • Save benhysell/9359124d604d4235822d to your computer and use it in GitHub Desktop.

Select an option

Save benhysell/9359124d604d4235822d to your computer and use it in GitHub Desktop.
NuSpec National Instruments Measurement Studio with Squirrel Distribution
Use with https://github.com/Squirrel/Squirrel.Windows
Add Squirrel nuget packages to solution
Modify AssemblyInfo.cs as described in Setup.cs
Modify startup code with code in Setup.cs
Add an 'update' method and execute an update and then restart of app
Host nuget packages on asp.net with https://www.nuget.org/packages/NuGet.Server/, place output of Squirrel in 'Packages' folder
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>ApplicationNameNoSpaces</id>
<version>$version$</version>
<authors>benh</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Application Name</description>
</metadata>
<files>
<file src="C:\Windows\System32\cvitdms.dll" target="lib\net45\cvitdms.dll" />
<file src="C:\Windows\System32\msvcr100.dll" target="lib\net45\msvcr100.dll" />
<file src="C:\Program Files (x86)\National Instruments\Shared\MKL\MKL70\libguide40.dll" target="lib\net45\libguide40.dll" />
<file src="C:\Program Files (x86)\National Instruments\Shared\MKL\MKL70\mkl_def.dll" target="lib\net45\mkl_def.dll" />
<file src="C:\Program Files (x86)\National Instruments\Shared\MKL\MKL70\mkl_lapack64.dll" target="lib\net45\mkl_lapack64.dll" />
<file src="C:\Program Files (x86)\National Instruments\Shared\MKL\MKL70\mkl_p3.dll" target="lib\net45\mkl_p3.dll" />
<file src="C:\Program Files (x86)\National Instruments\Shared\MKL\MKL70\mkl_p4.dll" target="lib\net45\mkl_p4.dll" />
<file src="C:\Program Files (x86)\National Instruments\Shared\MKL\MKL70\mkl_p4p.dll" target="lib\net45\mkl_p4p.dll" />
<file src="C:\Program Files (x86)\National Instruments\MeasurementStudioVS2012\DotNET\Assemblies\Current\NationalInstruments.Analysis.Enterprise.dll" target="lib\net45\NationalInstruments.Analysis.Enterprise.dll" />
<file src="C:\Program Files (x86)\National Instruments\MeasurementStudioVS2012\DotNET\Assemblies\Current\NationalInstruments.Common.dll" target="lib\net45\NationalInstruments.Common.dll" />
<file src="C:\Program Files (x86)\National Instruments\MeasurementStudioVS2012\DotNET\Assemblies\Current\NationalInstruments.Common.Native.dll" target="lib\net45\NationalInstruments.Common.Native.dll" />
<file src="C:\Program Files (x86)\National Instruments\MeasurementStudioVS2012\DotNET\Assemblies\Current\NationalInstruments.DAQmx.dll" target="lib\net45\NationalInstruments.DAQmx.dll" />
<file src="C:\Program Files (x86)\National Instruments\MeasurementStudioVS2012\DotNET\Assemblies\Current\NationalInstruments.MStudioCLM.dll" target="lib\net45\NationalInstruments.MStudioCLM.dll" />
<file src="C:\Program Files (x86)\National Instruments\MeasurementStudioVS2012\DotNET\Assemblies\Current\NationalInstruments.NiLmClientDLL.dll" target="lib\net45\NationalInstruments.NiLmClientDLL.dll" />
<file src="C:\Program Files (x86)\National Instruments\MeasurementStudioVS2012\DotNET\Assemblies\Current\NationalInstruments.Tdms.dll" target="lib\net45\NationalInstruments.Tdms.dll" />
<file src="C:\Program Files (x86)\National Instruments\Shared\Analysis\nianlys.dll" target="lib\net45\nianlys.dll" />
<file src="C:\Program Files (x86)\National Instruments\Shared\Tdms\tdms.dll" target="lib\net45\tdms.dll" />
<file src="bin\x86\release\**\*" target="lib\net45" />
</files>
</package>
@ECHO off
REM **** Make sure the version was passed in ****
IF "%1" == "" GOTO HELP
IF "%1" == "-h" GOTO HELP
IF "%1" == "/h" GOTO HELP
IF "%1" == "/?" GOTO HELP
REM **** Create the NuGet package for Squirrel to use ****
IF NOT EXIST BuildPackages MD BuildPackages
..\.nuget\nuget pack ApplicationName.nuspec -Version %1 -OutputDirectory BuildPackages
IF NOT ERRORLEVEL 0 (
ECHO Creating the NuGet package failed.
GOTO EXIT
)
ECHO Attempting to build the installer using Squirrel.
..\packages\squirrel.windows.0.9.1\tools\Squirrel.exe --releasify BuildPackages\ApplicationName.%1.nupkg
IF NOT ERRORLEVEL 0 (
ECHO Building the installer failed with an error.
ECHO The log file at ..\packages\squirrel.windows.0.9.1\tools\SquirrelSetup.log might help.
GOTO EXIT
)
ECHO Successfully created Releases\Setup.exe.
GOTO EXIT
:HELP
ECHO Usage: release version
ECHO Example: release 1.1.0.25
:EXIT
//Add to AssemblyInfo.cs
[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")]
//add in startup code for applicaiton to subscribe to Squirrel Events, do as soon as possible
using (var mgr = new UpdateManager(Settings.Default.ServerPackageUpdateUrl, "ApplicationName", FrameworkVersion.Net45))
{
SquirrelAwareApp.HandleEvents(
onInitialInstall: v => mgr.CreateShortcutForThisExe(),
onAppUpdate: v =>
{
mgr.CreateShortcutForThisExe();
},
onAppUninstall: v => mgr.RemoveShortcutForThisExe()
);
}
//To update application call Update, note this does not provide any status updates and does a 'hard' update and restart to
//start running the new version
private async void Update(object sender, System.Windows.RoutedEventArgs e)
{
//use a URL or a folder
//using (var mgr = new UpdateManager(@"C:\Jobs\Releases", "ApplicationName", FrameworkVersion.Net45))
using (var mgr = new UpdateManager(Settings.Default.ServerPackageUpdateUrl, "ApplicationName", FrameworkVersion.Net45))
{
var updateInfo = await mgr.CheckForUpdate(); //one can learn more about available updates by checking updateInfo
await mgr.UpdateApp();
}
UpdateManager.RestartApp(); //restarts the app no matter what
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment