Extract file on successful installation using NSIS installer.nsh include script in electron-builder - nsis

Aim:
Install MS C++ Redistributable exe -> program (app) install -> after successful installation extract a file (that is unpacked by the installer).
Background:
I need to package django backend in electron app. django backend contains about 29k files. When creating installer using electron-builder, it takes 10 minutes to install. So, I thought why not tar the backend, package it in exe using electron-builder and extract it later. Now installation happens within 1 min and extraction time (calculated extracting the folder separately) is about 2.5 mins. So effectively, total install time is now 3.5 mins which is a huge improvement.
Problem:
Problem is the app launches as soon as the installation finishes and onInstSuccess function does not work. How can I extract files post installation while stop the app from starting till the extraction has finished?
I've been stuck at it for hours now. Thanks in advance.
package.json file is as follows
"nsis": {
"installerIcon": "assets/resources/builder/icon.ico",
"uninstallerIcon": "assets/resources/builder/icon.ico",
"installerHeaderIcon": "assets/resources/builder/icon.ico",
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"shortcutName": "DCMIO",
"include": "nsis/installer.nsh"
}
nsis/installer.nsh file is as follows
!macro customInstall
ExecWait '"$INSTDIR\resources\assets\msvc_redistributable.exe" /passive /norestart'
!macroend
Function .onInstSuccess
ExecWait '"$INSTDIR\resources\assets\bsdtar.exe" -xzf "$INSTDIR\resources\assets\backend.tar.gz" -C "$INSTDIR\resources\assets\"'
FunctionEnd

Related

Running custom scripts during build/compile in node js visual studio

I have created a sample app https://github.com/ajithvallabai/TestMethod in Visual studio 2019 . I want to run prebuild and build scripts in package.json https://github.com/ajithvallabai/TestMethod/blob/master/TestMethod/package.json#L10-L11 when we build the solution . Is there any way to do it ?
(In this app there is no build-events option in Project>properties
This method is only working for "buid" command https://learn.microsoft.com/en-us/visualstudio/javascript/compile-typescript-code-npm?view=vs-2022 that too it needs additonal files like .ts files .tcx files . but i want to run custom commands.
You can give answer for VS19/VS22 also

Pack & unpack node_modules of an Electron Native application to be patched

First of all, I am generating an electron native application using electron-builder, npm and npx.
The next commands/steps are being executed to compile and generate the electron native application:
npm run build -- --prod --build-optimizer (to compile app)
npx electron-builder build --windows (to generate an electron windows app)
Later, I obtain a myApp folder which contains:
/win-unpacked
electron-builder-effective-config.yaml
myApp.exe
My application uses the node_modules folder which contains all node dependencies used in my application.
My question is: are there any way to unpack the native application or similar and patch new changes inside node_modules?
After perform an investigation, I have discovered that node dependencies are packed in system cache inside an app.asar file which contains a dist folder with some .js files.
In developer tools:
Inside app.asar:
Are there any way to "deploy" node modules folder with the aim to perform patch operations of each package and change the code inside node modules folders?
I will appreciate any kind of help.
Asar is a read only archiv format, so you cant patch any files in the archive.
But what you can do is to disable the asar option in your build config.
So in your package.json define it like this:
"build": {
"appid": "........",
"win": {........},
"asar": false
}
if you build this, there is no asar archive anymore and you can overwrite any file...
what you can also do is using asar programatically. So you can unpack the asar archive, updating files and package new archive. See here how you can use it
Contrary to what is being said here, patching a .asar archive is totally possible. I have published a library on NPM called patch-asar that does specifically this.

Binary executable included in NPM dist installation package

Is it possible to include a binary executable in NPM package? I am struggling to do so on macOS.
I am working on an electron application which uses SVN. Using svn-spawn package I am able to communicate with the svn if it's installed on the machine. However, I would like to not to install SVN and my application separately.
Since SVN works as a single executable - either svn.exe on Windows or svn on macOS, I can edit the following block in node_modules/svn-spawn/lib/svn.js
var Client = function(options) {
this.option({
program: '<path_to_svn>/svn.exe'
}).option(options);
};
After I package it:
works on Windows (even after uninstalling svn - meaning svn became a part of the application)
works on macOS when svn is still in the directory
doesn't work on macOS when svn is deleted
What is the right way of including executables like that in npm installation?
For anyone with the same problem - this tread helps:
bundling precompiled binary into electron app
You can copy over a file by updating package.json
"build": {
"extraFiles": [
{
"from": "resources/${os}",
"to": "Resources/bin",
"filter": ["**/*"]
}
],
Then referencing this file from your script.

Running a self-contained ASP.NET Core application on Ubuntu

I've published an ASP.NET Core application as a self-contained application targeting Ubuntu. The publish seems to work fine. I've copied the files to a pretty vanilla Ubuntu machine. Now, how do I run my application?
My understanding is that because it is a self-contained .NET Core application I do not need to download and install .NET Core anything. My application should contain everything it needs.
All tutorials seem to say I should call dotnet run. However, the "dotnet" command line doesn't exist (is it supposed to be published into the self-contained folder??) So if I call it, I get "command not found". Of course I could download .NET Core, but doesn't that go against the whole self-contained concept?
Here is a sample of the files I'm copying over:
Answer
Now, how do I run my application? My understanding is that because it is a self-contained .NET Core application I do not need to download and install .NET Core anything. My application should contain everything it needs.
You are correct. Run the executable.
When you create a self-contained app, the publish output "contains the complete set of files (both your app files and all .NET Core files) needed to launch your app." That includes the executable.
Example Self-Contained Deployment
Here is the output of dotnet publish -c release -r ubuntu.14.04-x64 for a simple self-contained application. Copy the publish directory to Ubuntu and run the executable.
C:\MyApp\bin\release\netcoreapp1.0\ubuntu.14.04-x64\publish\
...
libsos.so
libsosplugin.so
libuv.so
Microsoft.CodeAnalysis.CSharp.dll
Microsoft.CodeAnalysis.dll
Microsoft.CodeAnalysis.VisualBasic.dll
Microsoft.CSharp.dll
Microsoft.VisualBasic.dll
Microsoft.Win32.Primitives.dll
Microsoft.Win32.Registry.dll
mscorlib.dll
mscorlib.ni.dll
MyApp <------- On Ubuntu, run this executable
MyApp.deps.json and you will see Hello World!
MyApp.dll
MyApp.pdb
MyApp.runtimeconfig.json
sosdocsunix.txt
System.AppContext.dll
System.Buffers.dll
System.Collections.Concurrent.dll
System.Collections.dll
...
C:\MyApp\project.json
{
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": "1.0.1"
}
}
},
"runtimes": {
"ubuntu.14.04-x64" : {},
"win10-x64" : {}
}
}
C:\MyApp\Program.cs
public class Program
{
public static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
}
}
See Also
This document differentiates between framework-dependent and self-contained deployments.
Follow the below steps to run your application:
Publish your application as a self contained application:
dotnet publish -c release -r ubuntu.16.04-x64 --self-contained
Copy the publish folder to the Ubuntu machine
Open the Ubuntu machine terminal (CLI) and go to the project directory
Provide execute permissions:
chmod 777 ./appname
Execute the application
./appname
Author: Harit Kumar
Original answer here: How to run a .NET Core console application on Linux
It's worth noting that with the .NET Standard 2+, there are two required steps:
Edit the .csproj file and add a line with a list of target runtimes:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<!-- Add this with the required runtimes -->
<RuntimeIdentifiers>win10-x64;osx.10.11-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
</PropertyGroup>
Restore and build the app: dotnet restore && dotnet build -c release -r RUNTIME
Where RUNTIME is one of the runtimes listed in the .csproj file.
Importantly note that you cannot do this without the .csproj file edit and calling dotnet restore, or the runtime will not be downloaded from NuGet, and the -r ... flag will not work.
You may want to check out dotnet-packaging as well. It includes a dotnet deb command line utility which allows you to create a .deb file (i.e. a Ubuntu installer) which you can use to install your app on Ubuntu. It should make deployment easier for you.
To get started, you'll first need to add this section to your .csproj file:
<ItemGroup>
<PackageReference Include="Packaging.Targets" Version="0.1.45" />
<DotNetCliToolReference Include="dotnet-deb" Version="0.1.45" />
<ItemGroup>
Then, run dotnet restore and dotnet deb -c Release -r ubuntu.18.04-x64 -f netcoreapp2.0. This will create a .deb file you can use to deploy your application to Ubuntu.

Running a simple Console App in Dnx/AspNet5 and will not run outside of Visual Studio?

I've written a small simple console app as a AspNet5 Console Package
namespace ConsoleApp1
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello world");
Console.ReadLine();
}
}
}
Running this through debug in Visual Studio and I get a command window with Hello World written in. However when I compile this with project properties "Produce outputs on build" I get an artifacts\bin\ConsoleApp1\Debug\app directory produced with the following output
and a dnx46 directory with
Contents of the .cmd file in the app directory is
#dnx --appbase "%~dp0." Microsoft.Dnx.ApplicationHost ConsoleApp1 %*
Contents of the project.json file is the following
{
"version": "1.0.0-*",
"description": "ConsoleApp1 Console Application",
"authors": [
"Doug"
],
"tags": [
""
],
"projectUrl": "",
"licenseUrl": "",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"ConsoleApp1": "1.0.0"
},
"commands": {
"ConsoleApp1": "ConsoleApp1"
},
"frameworks": {
"dnx46": {
"System.Console": "4.0.0-beta-23516"
}
},
"entryPoint": "ConsoleApp1",
"loadable": false
}
Double clicking the cmd file won't run the program. I put in the ReadLine() code to pause the app on run to see what the output would be, but I see it flash then go away. I've also tried running it from the app directory in powershell using the following command "dnx ConsoleApp1" but it won't run. This is just a simple console application and shouldn't be this hard to run but I can't seem to get it to run outside of the visual studio environment. What am I doing wrong????
Update 1
I got this to run executing from the directory of the src, but I can't seem to run the outputs in the same fashion from the artifacts directory. Any ideas???
PS C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\src\ConsoleApp1> dnx run
Hello world
Just as an FYI here is my dnvm list output
UPDATE 2
Below is the output if I change to the directory of the ".cmd" file and try executing it manually in an open window which is why it just terminates and closes... due to the contents of the .cmd file I figured this at the very least would work... I will try the dnu publish shortly. If the publish works then what is the point of the .cmd files produced in the artifacts directory.
UPDATE 3
Ok, so I ran the dnu publish command from the directory that contains the project source files. The output is below.
The resulting ".cmd" file highlighted in the directory structure was double clicked and the cmd.exe window appeared with the correct output. The directory structure and output are below.
However this made me curious... when I run the same dnu publish command in the artifacts directory produced by the compile and "Produce build outputs" option checked and the resulting .cmd file would not execute the console program??? What is the difference between the output in the artifacts directory and the files in program source that allow everything to be pulled together to execute.
PS... this seems like ALOT of work just to get a console program to run outside of visual studio! Is this the intent of DNX? No exe's? just curious
UPDATE 4
I ran the following in the directory for the output artifacts... the result was still no runable version of the program in the artifacts directory but the output files look almost identical to that of what was in the /src directory bin.
I apologize for not taking a screen shot but my screen wasn't big enough to hold everything at once.
PS C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\artifacts\bin\ConsoleApp1\Debug\app> dnu restore
Microsoft .NET Development Utility Clr-x86-1.0.0-rc1-16231
CACHE https://www.nuget.org/api/v2/
Restoring packages for C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\artifacts\bin\ConsoleApp1\Debug\app\project.json
Writing lock file C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\artifacts\bin\ConsoleApp1\Debug\app\project.lock.json
Restore complete, 123ms elapsed
NuGet Config files used:
C:\Users\Doug\AppData\Roaming\NuGet\nuget.config
Feeds used:
https://www.nuget.org/api/v2/
PS C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\artifacts\bin\ConsoleApp1\Debug\app> dnu publish --runtime active --no-source
Microsoft .NET Development Utility Clr-x86-1.0.0-rc1-16231
Copying to output path C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\artifacts\bin\ConsoleApp1\Debug\app\bin\output
Using Project dependency app 1.0.0 for DNX,Version=v4.6
Packing nupkg from Project dependency app
Source C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\artifacts\bin\ConsoleApp1\Debug\app\project.json
Target C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\artifacts\bin\ConsoleApp1\Debug\app\bin\output\approot\packages\app\1.0.0
Building app for DNX,Version=v4.6
Using Project dependency app 1.0.0
Source: C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\artifacts\bin\ConsoleApp1\Debug\app\project.json
Using Project dependency ConsoleApp1 1.0.0
Source: C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\src\ConsoleApp1\project.json
Using Assembly dependency fx/mscorlib 4.0.0
Source: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\mscorlib.dll
Using Assembly dependency fx/System 4.0.0
Source: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.dll
Using Assembly dependency fx/System.Core 4.0.0
Source: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Core.dll
Using Assembly dependency fx/Microsoft.CSharp 4.0.0
Source: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\Microsoft.CSharp.dll
dnu : error CS5001: Program does not contain a static 'Main' method suitable for an entry point
At line:1 char:1
+ dnu publish --runtime active --no-source
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (error CS5001: P... an entry point:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Build failed.
0 Warning(s)
1 Error(s)
Time elapsed 00:00:00.3519605
Total build time elapsed: 00:00:00.3550713
Total projects built: 1
Using Project dependency ConsoleApp1 1.0.0 for DNX,Version=v4.6
Packing nupkg from Project dependency ConsoleApp1
Source C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\src\ConsoleApp1\project.json
Target C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\artifacts\bin\ConsoleApp1\Debug\app\bin\output\approot\packages\ConsoleApp1\1.0.0
Building ConsoleApp1 for DNX,Version=v4.6
Using Project dependency ConsoleApp1 1.0.0
Source: C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\src\ConsoleApp1\project.json
Using Assembly dependency fx/mscorlib 4.0.0
Source: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\mscorlib.dll
Using Assembly dependency fx/System 4.0.0
Source: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.dll
Using Assembly dependency fx/System.Core 4.0.0
Source: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Core.dll
Using Assembly dependency fx/Microsoft.CSharp 4.0.0
Source: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\Microsoft.CSharp.dll
Exported application command: ConsoleApp1
ConsoleApp1 -> C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\src\ConsoleApp1\bin\Debug\ConsoleApp1.1.0.0.nupkg
ConsoleApp1 -> C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\src\ConsoleApp1\bin\Debug\ConsoleApp1.1.0.0.symbols.nupkg
Build succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:00.2780556
Total build time elapsed: 00:00:00.2790409
Total projects built: 1
Adding NuGet package C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\src\ConsoleApp1\bin\Debug\ConsoleApp1.1.0.0.nupkg to C:\Users\Doug\Documents\Visua
l Studio 14\Projects\WebApplication2\artifacts\bin\ConsoleApp1\Debug\app\bin\output\approot\packages
Installing ConsoleApp1.1.0.0
Add complete, 46ms elapsed
Removing C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\src\ConsoleApp1\bin\Debug\ConsoleApp1.1.0.0.nupkg
Removing C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\src\ConsoleApp1\bin\Debug\ConsoleApp1.1.0.0.symbols.nupkg
Bundling runtime dnx-clr-win-x86.1.0.0-rc1-update1
Time elapsed 00:00:01.1140479
PS C:\Users\Doug\Documents\Visual Studio 14\Projects\WebApplication2\artifacts\bin\ConsoleApp1\Debug\app>
Here was the directory output resulting in running the command dnu publish in the artifacts directory... the output was the same but the .cmd file wouldn't run
Can you tell me the difference between running against the /src directory of the project vs the /artifacts directory on produce outputs?
PS: sorry for such a long post, just really trying to wrap my head around this DNX stuff! And again thanks for your help
Since you listing multiple problems, I'm going to address them individually.
Double clicking the cmd file won't run the program. I put in the ReadLine() code to pause the app on run to see what the output would be, but I see it flash then go away.
That's expected. The cmd file launches the application in a new console and when the process terminates, the console closes.
You have a few options:
Just like you did, add a ReadLine at the end of the program.
Run the cmd file from a console.
Keep the console open after run by following the instructions in this question Batch files : How to leave the console window open
Update 1 I got this to run executing from the directory of the src, but I can't seem to run the outputs in the same fashion from the artifacts directory. Any ideas???
"Produce outputs on build" doesn't produce runnable executables (yes, it's confusing), but nuget packages.
So, in the dnx world:
If you produce outputs on build, that's the equivalent of running dnu pack.
If you want to create a folder that has a runnable app, you have to run dnu publish (or Publish from VS). Depending on what arguments you pass, you will get a folder that has the runnable app, its dependencies and, optionally, the runtime.
So, a self contained published app can be produced with:
dnu publish --runtime <runtime name or "active"> --no-source
The --no-source argument will precompile the projects for which you have sources (this is the closest you'll get to a classic C# app). Without that argument, the sources will be compile on the fly every time the app starts.
The default output of the publish command is under bin\output

Resources