how to set path in MSI installer? - c#

I am using VS2008 setup project to build our msi installer. I have moved some dll files from the default location (root folder of the installation) to a custom bin directory. I think I need to set path in somewhere (registry?) to tell the application the new loation of those dll files. How to do this? thanks,

Just open up the .vdproj file in notepad and search for the dll files you moved. Then adjust the dll path (usually called SourcePath). You should not edit anything in the Registry! Only edit this file.

If these are references in your project, I would remove the references and add them back using the Browse tab of the Add Reference dialog.

Related

How can I run an embedded .exe file in C# Windows Forms applications?

How can I run an embedded .exe file (installer) in C# Windows Forms applications the easiest way?
I just want to click a button and an installer should open. My .exe file's name is setup.
If I try Process.Start(setup.exe); I get an error:
The name 'setup' does not exist in the current context
And if I try
System.Diagnostics.Process.Start("setup");
it will open folder C:\Windows\System32\setup.
If what you expect is the easiest way, then don't embed setup.exe as a resource, but as Content.
(Add setup.exe to your project, and right click on setup.exe in Solution Explorer to edit properties, set as content, and select Copy if newer.)
Another option if setup.exe is a project of your Visual Studio solution, is to automatically copy setup.exe in the output directory of the launcher project: Add a reference to setup.exe if it belongs to the solution, so it is automatically copied every time you compile and there was a change.
Last is the code that is pretty easy - you already have it, actually:
System.Diagnostics.Process.Start("HelloWorld.exe");
If needed, you can change the current directory:
Environment.CurrentDirectory = #"c:\someSetupExeDir";
But better, you can use Path.Combine:
String fullPath = Path.Combine(directoryPath, fileName);

appname.exe.config not created on windows application

When I build a windows application. It does not work because it cannot read my app.config file. I looked in the bin directory and it does not have the appname.exe.config file. If I manually copy over the app.config and rename it the appname.exe.config the application will work..but when I build the project this file is never created automagically. What am I missing? Why is my project not creating it? I have looked through the whole folder structure and there is no other config files.
Everyone here is giving you false information I think. I think #bowlturner had it right. According to Microsoft, you do need to set the app.config's Copy to output directory property to either Copy Always or Copy if newer. From Microsoft's MSDN Site:
When you develop in Visual Studio, place the source configuration file for your app in the project directory and set its Copy To Output Directory property to Copy always or Copy if newer. The name of the configuration file is the name of the app with a .config extension. For example, an app called myApp.exe should have a source configuration file called myApp.exe.config.
Visual Studio automatically copies the source configuration file to the directory where the compiled assembly is placed to create the output configuration file, which is deployed with the app.
The correct settings are:
Build Action = None
Copy to Output Directory = Do not copy
and very important, the project file needs to contain this element:
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
The only thing that worked for me was to delete bin\ and obj\ entirely. Rebuild and the file is created fine.
Look on App.config properties, should be:
BuildAction: None
CopyToOutputDirectory: Do not copy
Custom tool and custom tool namespace should be empty
Also try to Rebuild project. Right click on project -> Rebuild
Assuming you're using Visual Studio click your config file in the Solution Explorer and and in the Properties panel set Copy To Output Directory to something other than Do Not Copy.

how to set the folder of destination when I use local copy?

I have a project in Visual Studio 2010 and in this project I have a "lib" foleder in which I have the external dll that I need. In this case, the libraries of SQLite.
Well, I can set hte reference to the principal dlls, SQLite.dll and SQLite.Linq.dll. In this case, the dll are copy in the main folder of the application.
However, I need also the SQLiteinterop.dll. I have tried to add a reference to this dll, but I get the error that it is not a valid COM component. So the way that I find to copy the dll is marked as local copy in the properties of the dll that is in the "lib" folder.
However, this copies the dll in a subfolder "lib" in the main application folder and I need to copy in the main folder.
Is there any way to set in visual studio where to copy each dll?
Thanks.
I would suggest using a Build Event, retrievable in the Properties of the Project.
Here you can make a Post-build event which copies the file to the Build folder.
Something like:
copy /Y "$(SolutionDir)lib\$(ProjectName)\sqllitefile.dll" "$(TargetDir)\$(ProjectName)\sqllitefile.dll"

Application Executable Path C#

I've added an executable to my Visual Studio 2010 C# Solution. In the properties of this executable, the executable path is a full path ("C:\Test\MyProgram\MyProgram.exe")
When I deploy my solution (with installshield) on a new PC, the executable is part of the deployed solution together with some source files and the solution file. So far so good.
But when I open the installed solution file (in Visual Studio 2010),
I'm not able to build it because It can't find the executable in the specified path:
("C:\Test\MyProgram\").
Here is the question: How can change the full path of the executable, so it gets the path of where the solution is installed on the new PC. Something like :
"[InstallDir]\MyProgram.exe"
Thanks
Update: I found out that you can use relative path in Application's Executable path. Thanks for all your answers.
You could use TargetDir property
I am just thinking off the top of my head here. There may be a much simpler way. I'm thinking you might want to create a Custom Action that runs at the end of your installer that manually opens the .xxproj file, and manually edits the path of the reference. As another poster stated, you can get the new path from the TargetDir property: http://msdn.microsoft.com/en-us/library/aa372064%28VS.85%29.aspx
Example of creating Custom Actions: http://msdn.microsoft.com/en-us/library/9cdb5eda(v=vs.80).aspx
Add your Executable to your Project TO The Main Dir, right click-> Copy To OutPutDirectory -> Copy
this is easiest way to make your file to copy to your target dir, and have your SourceControl Visual studio plugin manage it.
Your executable should be be somewhere in your project source files structure, perhaps in a subfolder. When you add this executable file to project it should then be added on a relative path which is what you want. If this is not happening you should manually edit csprj file. To do this, right click on project, unload it, right click again and edit project file.
Of course, your executable file should have its property Build Action set to None and Copy to output Directory to what you want.
If for some reason you cannot add this executable directly into your project files structure I'd suggest to use pre-build event to copy it from where it exists into your project files.

How do I configure VS installer to put files in LocalApplicationData

Everything in Visual Studio seems to lead one to putting data files with the application.The app.config goes there, when I create an .XML data file, there is a Copy to Output property that will automatically copy that file to the exe folder. Howerver, it seems that under Vista and Win7 UAC doesn't want the application to be able to write data to any file in the application directory. So I'm changing my evil ways so that I use the LocalApplicationData folder for files I want to read and write. (I just read the app.config so I'm leaving it alone)
I'm using a VS2010 Visual Studio Installer project to create the installer for this app and I can't seem to find a way to target the folder for my .xml file to the LocalApplicationData folder. I can click on the file and see a Folder property but the dialog only has options for Application Folder, User's Desktop and User's Program Menu. Is there some way to do this in the installer or do I have to write code that checks for the file and copies it over from the .exe folder when it doesn't exist? I figure I'm late to this particular party and there must be a canonical way of handling this.
Also, I'm wondering about debugging, is there something similar to the copy if newer functionality in the build process that will now copy this .xml file automatically over to the LocalApplicationData folder whenever I update it?
The Setup project doesn't expose LocalApplicationData in the Special Folders list. You can use it anyway by doing this:
Add a Custom Folder and set the DefaultLocation property to [LocalAppDataFolder]

Categories

Resources