Setting external dependencies in a .Net Core (c#) app - c#

My application will need to use an external command line app at some point. I will then create a process and then call the external executable. The command line tool is available for Unix and Windows systems and I was wondering what is the best way to set the dependencies in my .NET Core app.
Of course, I could write code to download the executable for the current OS where the app is running on in Base directory and then reference it in the app but it seems pretty wasteful as if the user has already install the commandline via yum or apt-get then it doesn't make sense to re-download the binaries.

There can be two ways to solve this problem.
Check in the installer:
I would suggest to add check in installer of your .NET Core app, to see if the dependency is present by looking at windows registry (or any similar table depending on OS where you are installing your application).
You can stop installation and ask user to install the dependency first.
The other option is to download the utility as a part of your installation process and install it.
Check in the app:
If you do not want to do this during installation, you can also do this either during app startup or during the startup of your module which needs this external dependency. You can detect and if it is not available, can show a nice information message to user to download and install it.
The decision will totally depend on the design of your application.

Related

Programmatically Installing Windows Service from Application

I currently have a windows service that needs to run in the background while a main application I have written handles UI and other tasks. I install and maintain the GUI application using ClickOnce Deployment and would like to find a way to bundle my Windows Service in as well.
They are in separate projects at the moment since I was still learning how to use the Windows Service.
My question is, is it possible given MyService.exe that I install and start MyService.exe from MyApp.exe? I can assume that I have access to InstallUtil.exe and could write a script to install and run it manually, but I would like a cleaner solution if there is one.
The only resources I've found all seem to assume I want to have the Service install itself, which is not the case.
In general, ClickOnce can't be used to install services. There is typically a lack of permissions, but also the location is incorrect, etc. For details, see MSDN on Choosing Between ClickOnce and Windows Installer for more details.
If you want to install a service, you should do a traditional installation.

How can I add window Service in C#/ install it and Run exe(My Job.exe) through this Window Service?

Actually I want to run exe file(My Job.exe) Through window Service in C# but window service should be started automatically when I start the Computer?
I have already added Window Service (MyService) manually. I have also setup project of My application where I also added this service so that I can also be installed when I install my Application.
I have serviceInstaller1 with property
StartType=Automatic;ServiceName=MyService.
I also have serviceProcessInstaller1 with Property
Account=LocalSystem;
When I run this my Applicationo gets installed but MyService don't get installed and I also not see it in Service of Computer Management.
Could any body please help me I already spend two days on it but not finding proper guidline. thanks in Advance.
How is your application being installed? Did you create an installer (.msi file) for it? It sounds like you're trying to implement your own installer instead of using existing tool to do this.
I recommend Advanced Installer. It is a very powerful installer generator and has all the features you need in the free version, and more importantly, it's very easy to use. This tool lets you create an install wizard with the ability to patch and uninstall your software (including services, registry values, files, etc).
I recently have one project with windows service in VS2010 and .Net 4.5 and user OS will be Windows Server 2008. I was unable to create fully functional installation a long time, and still i dont have, but request are changed so no need for installation file. But i can give you advice "How to do".
If you don't have purchased version of InstallShield you need to find some other program for creating installation file.
For installation you need just to copy you .exe output of service and one batch file witch will have next content:
#ECHO off
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" "%~dp0%<filename>.exe"
pause
and then you need to run with administration rights this batch file.
Both files (.exe and .bat) must be in same folder.
You can delete pause command but then you will not see if registration of service was successfully.
Make sure that you have installed target .NET Framework on PC.
I hope that this will help you.
If you just need to run your exe file(My Job.exe) when the system starts up you could add your exe to the Windows Task Scheduler.
Is there any specific purpose for using a Windows service?
The reason that I am saying this is that you have a wide variety of options to invoke you exe as follows
Schedule based on common recurring events, i.e. When the computer starts or When a user logs on.
Schedule based on the calendar, i.e. Daily, Weekly, Monthly, or One time.
Advanced options like execution based on events, etc.

Auto Run CD With Application written using .net platform

We are building an application on .net, And it is an Image Viewer application uses .net 3.5.
And this application will be on a CD along with other images.
My Question is, is it possible to Auto Run this application when you insert a CD on a machine which DOESN'T Contain .NET Frame Work.
Or any other ways of building the application which runs from the CD.
Autorun is a feature of Windows. It does not have anything to do with .NET really. You can use it by placing apropriate files in the root of your CD.
See: http://en.wikipedia.org/wiki/AutoRun
In order to execute a .NET app WITHOUT .NET framework installed, point the Autorun.inf to an installer of you application, which would be deployed on the CD as well.
The application will fail to run directly when it cannot find the libraries it need.
What you can do is to create a non-.NET dependent bootstrapper, include the framework installer.
So when the CD auto run, run the bootstrapper, the bootstrapper will run the installer. Once installed, run the application.
No, you can't run .NET applications on a computer without the .NET Framework installed. That's a hard rule, and a pretty intuitive one, it seems to me. Somehow, this question still gets asked a lot.
But Auto Run has nothing to do with the .NET Framework. It's a feature provided by the Windows operating system designed to run your setup/installation program directly from the inserted installation medium without requiring any kind of user interaction.
So what you should be doing is creating a setup program for your .NET application. You can do this from within Visual Studio: just create a Setup Project instead of a Windows Forms Application. The setup program will take care of detecting whether or not the computer has the appropriate version of the .NET Framework installed, and installing it if necessary along with the application. The setup bootstrapper will be able to run without the .NET Framework installed, so you can create an autorun.inf file that simply specifies setup.exe as the application to be launched automatically.
I've used mono to do this a few times, not with the static linking as mentioned in the other answer, but by including the mono distribution on the cd (or a subset of it). Mono doesn't seem to do much in the way of modifying registry, system32, etc. So you can do an xcopy deployment of if, or CD deployment in this case. You'll end up running mono.exe
I think Mono supports some form of static linking that doesn't require installation. But I never tried it myself.

Update application silently while running

My App will be initially deployed with Windows Installer.
The key characteristics of the solution I am looking for include:
Support silent update while app is
running (or automatically restart
client)
Easy to maintain and manage packing
process
Avoid complex customizations or
installation scripts
Do you have any ideas on how can I achieve this? Even if it means to modify the app code to support any idea.
Application is .net 2.0
Have you considered using ClickOnce for deployment? It has a facility to programatically check for updates and optionally force them to be installed - see http://msdn.microsoft.com/en-us/library/ms404263.aspx
You can silently update your application by using the Restart Manager (available in Vista and Win7).
Don't forget that a user is not alway the administrator. Since Vista if you sign your Windows Installer package you can update the application without needing administrator rights from the current user.
For all this to work you need to install your application using the Windows Installer technology. You can use Wix to create an xml file and compile it to an .msi package. Wix integrates nicely with VS.
The Proxy Design Pattern will help you achieve this while this is the pattern used for plugins.
Another short explanation is with the Gang of Four - Proxy Design Pattern.
Having an eye out the Shadow Copying of assemblies is definitely useful for the trick, as you shadow copy your updated assembly to your application assemblies folder, then you can make your application aware of changes, then unload the old assembly and load the new one for the changes to take effect, that is, without even having to restart your application, and this will be absolutely transparent for the end-user.
A more simple approach might be the ClickOnce Deployment which you might be interested to read about following the sugested link.

Advanced installation regarding to C#

I want to make an advanced installer for my C# application. |I want my application continue its installation after the pre-requisites been installed.
My scenario is:
myApplication requires .net Framework 2
it redirects the user to the Microsoft website.
the user installs the framework.
the installation requires to restart the PC.
STOPPED INSTALLATION
After this step (after restarting) I want myApplication to continue the installation (go to the last stage of the installation)
Any suggestion on how I do this ?!?!
I would suggest taking a look at the nullsoft install system. Use the Modern UI theme and the DotNET macro (http://nsis.sourceforge.net/DotNET). That's everything that you are looking for prebuilt, for free, and you can be up and running with very little effort.
I've had experience releasing applications with this route and it works very well.
Things like InstallShield, or one of the other installer creation tools would be able to handle the pre-requisite side of things for you. If you want to roll your own, then you could check for the framework, perform the various steps you mentioned to install it, then add you setup application to the RunOnce registry key so it starts again on startup.
Looking at something that would handle all the pre-requisites etc for you would be my choice though :-)
Install in this order:
Install the .NET framework
Install your app.
Restart if needed.
You can create an installation project in VS2005/8 to handle installing your app and any needed dependencies.
Are you aware that your compiled c# app itself will do this? The bootstrapper compiled into a .Net exe will contain a redirect to get the framework with a working link to the microsoft website.

Categories

Resources