How to deploy properly? - c#

I am trying to make a software that will execute .exe installation files of some other software using c# vs2013. I have used
Process.Start()
I added the files to be extracted in my resources and then I gave the resources path of those files
Process.Start("C:\\Users\\Farjad\\Documents\\Visual Studio 2013\\Projects\\RoyalComputerProject\\RoyalComputerProject\\Resources\\wrar501.exe");
It works fine on my computer However if I try to run it on some other computer it gives me an error saying that specified files are missing. I think It is because of the path I am passing to Process.Start() is of my computer. How should I correct this? What path should I pass? or How should I deploy it?

Ship your app along with dlls and this exe file in a package so when you extract it on another computer, you will get something like
C:/.../Downloads/YourAppName/
- MyApp.exe
- SomeLibrary.dll
- Config.xml
- MyOtherApp.exe
And now, you need to get a correct path of the running assembly which you could do using
string path;
path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
I found this code on MSDN.
For testing purposes, put that exe in bin/Debug or bin/Release folder, depending on how you build your app (debug vs release mode).

Related

Write a file where the deployed .exe file is executed

I have a console application written in C#, and i want to write the output of my execution in a log file.
In my code actually i use this path : Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
It's working fine when i run with debug command in Visual Studio and my logfile is created and works well.
But when i publish my application, the path is not the local path where the .exe is executed but in my AppData folder ...
I tried many other syntax and all of them works in debug mode but not when i deploy my application.
I want to get the local path, where my .exe is executed to write a logfile here. Thanks.
I deploy it with Visual Studio, simply publish option.
I get a setup.exe and a .application file
Regards,
You in general can never hope to write a file in the same directory as your installed exe. Works when you debug it but not after you deploy it. Programs do not have write access to the C:\Program Files directories. How it ended up in AppData is a bit hard to guess, you would have to intentionally remove the manifest from the program so the OS treats you like a legacy XP program that is not UAC aware. Hmm.
Well, never go there, just use Environment.GetFolderPath() to obtain an AppData path, have your installer create that directory.
You can try getting the Entry Assembly instead (which in your case should be the executable you ran).
var entryAssembly = Assembly.GetEntryAssembly();
var file = Path.Combine(
Path.GetDirectoryName(entryAssembly.Location),
entryAssembly.GetName().Name + ".log"),

FileNotFoundException is occur while running Wpf application on 32bit machine

I created setup file using Inno setup.I have exe,dll and one xml file in my setup.
When I install on 64 bit machine it works fine means it take xml file from directory where exe is present.
But When I install same setup on 32 bit machine it take dll path but while accessing xml file it takes path of desktop where shortcut of exe is present and showing FileNotFoundException.
Thanks
Your application is most likely not specifying pathnames on the files it is trying to open, so it is expecting to find them in the current directory. Inno Setup by default does not set the "Start In" field on shortcuts its creates; this causes Windows to pick a directory itself, which usually won't be the directory containing your application.
In virtually all cases, this is something that should be corrected at the application level. Properly designed GUI applications should not expect to be started from a particular directory; they should always specify full pathnames on files they open. In Delphi or C++Builder, for example, it's possible to get the full pathname of the directory containing the application EXE by calling: ExtractFilePath(ParamStr(0)). To get the full path of a file named "File.txt" in the application directory, use: ExtractFilePath(ParamStr(0)) + 'File.txt'.
To get path of working directory of application while loading xml file in code.
string WorkingDir=System.AppDomain.CurrentDomain.BaseDirectory
XDocument temp_xdocument= XDocument.Load(WorkingDir+"file.xml");
It works for me.

Include Chromedriver In Your Application

I have developed several programs with selenium chromedriver. Getting the correct path to chromedriver on end users computer is sometimes an issue, how can I include the chromedriver exe in the program file, that it should automatically deploy and able to be used with messing around with the path to the driver file.
First you will need to add the exe to your project. Right click add existing item and navigate to the exe.
secondly you need right click on the exe in your project and get to the properties. set the exe to copy to output directory -> copy if newer or copy always.
this should get the file publishing with your installation. this all depends on how you are deploying, but with clickOnce or web deploy this will work. Ultimately setting the copy to output directory will get the exe into your bin folder on build.
If you need the location of the exe you should be able to use something like System.Reflection.Assembly.GetExecutingAssembly().Location to get the location of where the execution is taking place.

Open Minidump : No native symbols in symbol file

In a C# project, I create minidump at UnhandledException.
In my Dev machine, project source and bin are under path K:\projects\*MYPROJECT*, if I manage to let it crash in my Dev machine, everything work perfectly, I can open the minidump file and correctly see source code, callstack, threads etc.
End-user program path will obviously be different; as an example, in our Test machine project is installed under C:\*MYPROJECT*. It's deployed with pdb symbol files. Anyway, when I try to open the minidump, generated on that machine, on my Dev computer (where I have the source files), Visual Studio try to find the executable and pdb file under "Test Path" (C:\*MYPROJECT*) without of course find it.
I tried setting Symbol path to include K:\projects*MYPROJECT* without any result, so I recreated the same Test directory structure, creating C:\*MYPROJECT* and copying .exe and .pdb files under that directory. Now, Visual Studio is be able to find them, but it's saying "No native symbols in symbol file", and it doesn't let me see any source code.
How can I accomplish to load the correct Symbols?
To change the directory, Microsoft describes to open the immediate window and type .exepath [path] to change it.
You can also use .srcpath [path] and .sympath [path].
Finally came across a solution.
After weeks trying to figure out what I were missing, I've found that on my development machine I have a different Framework version (in details, I have v4.0.30319.18444 vs v4.0.30319.17929 on test machine). I still don't understand why I shouldn't be able to debug my application without having the exact Framework version, but the solution was to copy mscordacwks.dll and mscordbi.dll (both of them found in C:\Windows\Microsoft.NET\Framework) from the Test machine to the folder where the minidump is.
Reference:
Managed Minidump Debugging in SP1

Defining where files are installed

I am trying to deploy a .NET application as a ClickOnce Application, but I am having trouble defining where the application is installed. I need to know this because I have to include support files. I have already added the support files as "existing items". I had assumed that the program would install in Program Files, but it does not exist there. Instead, there is just a shortcut on the desktop. Can someone explain how/where the install path is defined using VS2012?
One solution I found was to use some of the Application class properties to determine where ClicOnce installed an instance of my program. But be aware that some those are deleted on uninstall of the program.
// To get the path for the executable file that started the application, not including the executable name.
PATH_RESOURCES = Application.StartupPath ;
For persistant data I created references to specific paths like :
PATH_USERDATA = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + #"\myAppName\";
if (!System.IO.Directory.Exists((string)PATH_USERDATA))
{
System.IO.Directory.CreateDirectory((string)PATH_USERDATA);
}
PATH_REPORTS = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + #"\myAppName\";
if (!System.IO.Directory.Exists((string)PATH_REPORTS ))
{
System.IO.Directory.CreateDirectory((string)PATH_REPORTS );
}
Clickonce application gets installed under the user profile, not the Program Files path.
On windows Vista and Windows 7, clickonce application path will be somewhere in c:\users\username\AppData\Local\Apps\2.0\
On Windows XP, clickonce application path will be somewhere in c:\document and Settings\username\LocalSettings\Apps\2.0\
Note that Clickonce application path is different everytime upon installation, I found the best way is to make your app to write its own app path to the reg key, this way you know exactly where the app path is by looking at the reg.
So as user831062 pointed out, ClickOnce apps get installed under the user profile, not the Program Files path. Because of this, the install directory is different on every machine and almost impossible to access directly.
The part that I was hung-up on, was where are the files that I have included in the project located, and more importantly - how do I access them?
Well, as mentioned IN THIS LINK, if you mark the file as a "data file", under:
Project Properties > Publish > Application Files > Publish Status
you'll be able to access them using something like:
textBox = File.ReadAllLines(ApplicationDeployment.CurrentDeployment.DataDirectory + #"\myFile.txt")).ToList();
If you don't mark it as a "data file", but rather as just an "Include (Auto)", it will just be located in the install directory itself, which can be accessed by calling the file directly using something like:
textBox = File.ReadAllLines(#"myFile.txt")).ToList();
Anyway, took me an hour or so to find this, so hopefully it helps someone else out.
If you have added your files to your project, set the property for "build action" to "content" and set "copy to output directory" to "copy always". This way, the files will be included in your deployment. When the application is run, retrieve the location of the assembly and look in the same relative folder as where they were included in the project. For example, if they are in the top folder of the build output directory (/bin/debug/ or /bin/release/), they will be included in the same folder as the executable, which you can discover using this:
System.Reflection.Assembly.GetExecutingAssembly().Location

Categories