Include config file after publish with WiX - c#

Scenario:
I have two applications, a Windows Forms App and a Windows Service App. The two applications work together, use same libralies (dll) and share the same configuration file (this file is not the app.config but a custom file).
Complications:
I have a website (webforms) where the user will enter information about configuring the software, this information will be saved in the database and from this information will be generated the configuration file. The site should generate build the project with the new configuration file and the page responds to the client's request with a link to download the .msi.
Problem:
How to generate an installer from a command line to be called by the web application after generating the configuration file. I researched and found the Windows Installer XML (Wix), but it seems to be necessary to compile the entire project every time someone downloads. It's possible leave the program compiled and only add the configuration file after?
Apretiate any helps

Light (the linker in the WiX Toolset) has a feature called "cab cache" which will re-use the cabinet files which are embedded in the resultant MSI. You would use the arguments -reusecab and -cc to enable this.
You'll still have to re-build the MSI when the user submits your form, but the build will be faster (cabinet generation is usually the longest part of the build process).

Related

How do I determine the web origin folder of a ClickOnce application?

I have an C# application that is deployed as a ClickOnce application. The installation files can live in one of three possible folders on our web server: Alpha, Beta, and Production. The user addresses the appropriate location in IE to start the application: www.foo.com/Alpha, www.foo.com/Beta, or www.foo.com/Prod. In testing, we copy the installation files to Alpha first, then (when it passes testing) to Beta, then (when it passes user acceptance), to production. There is no recompilation.
What I want to know is whether there is any way the C# code can know at runtime which version it is: Alpha, Beta, or Production. It would be based only on which folder the ClickOnce installation files were located in. Remember that there has been no recompilation.
Any clues?
Thanks!
You could do this with a custom manifest element, but it will require some post-build processing.
The application can access the manifest file simply by opening a file stream on the AppName.exe.manifest file, and parsing the XML to locate and read the custom element. The manifest is deployed to the same directory as the executable.
When the application files are copied to a web server folder, simply modify the manifest to append the custom element (it could technically even be an XML comment, parsed with simple text comparison, if you don't want to use an XML parser).
After the manifest is modified (in each folder), it will have to be re-signed with the mage.exe signing tool.
You can automate this with a shell script fairly easily. On the whole, however, it would probably be a lot simpler to just build different actual versions.

C# .msi Installer Creation without <My Exe Name>.exe.config

When I create .msi file for C# windows application, the file <myexename>.exe.config automatically comes in the installation path after installing the .msi setup file.
How to exclude .exe.config file?
I think it is to be done during the Set up creation process itself.
Please advice.
<myexename>.exe.config is a config file (App.config) of your application.
when you create installer for any windows application, it will autometically include it.
it is necessary, for example you stored your application database connection string in that or may be other settings also
so when you execute your application then your application myexename will look into <myexename>.exe.config for some settings as well for some necessary data required.
still, if you want to exclude it, perform the following steps:
1)Right click on installer project -> View -> File System
2)In Application Folder, Right Click on Primary Output of your application and select Properties Window
3)In Properties, Select Exclude Files
4)Click on Add Filter
5)Enter app.config in text and press ok
now rebuild your project and install the .msi
<myexename>.exe.config will be removed from your installation directory

Visual Studio 2013 windows forms application with Resource file using c#

I have created windows forms application in C# VS 2013 with resource file (to maintain configurations). I created a Task in 'windows task scheduler' with the exe of the application (I copied 'exe file and resouce related file' to another envirnonment). when I run task, its running without any issues.
My intention of using resource file is to change configurations at any time without building the application.
But when I change configurations in application, if I update resource file in above mentioned environment, application using old configurations. when I copy new exe file its working with new configurations.
Please let me know is it correct way or guide me how to schedule 'windows forms application' in 'windows task scheduler' with resource file.
Thanks in advance,
Krishna.
You're confusing resx files and config files. You should use the second one. Here is good example.
Outside of ASP.NET, there isn't an easy way to use resource files in this way, resource files (.resx) are XML files which are build into a binary formal .resrouce file and embedded into the application assembly during build time, this is why any changes are ignored.
However you can put settings in your .config file in the appsettings section or build your own configsection, this way when the application runs again it will read the settings with your changes from this file.
You can also have a custom Xml/Json/Ini file and read from it using with your own code, but for simple settings, use appsettings section in the app.config file.
https://msdn.microsoft.com/en-us/library/aa903313(v=vs.71).aspx

How to find difference between the content of .exe and .msi (installer)

I recently took charge of a new system, it is a windows application written in C#, an installer (.MSI) file is created for its distribution. When I install the software it installs properly but it crashes on start. Then if I run the .exe file once for the application, the installed software starts working.
My observation is that .EXE installs some missing bit which is required by .MSI file. Is there a way I can find what files are missing in .MSI file ?
UPDATE on 09-08-2014:
I have found WER4A29.tmp.WERInternalMetadata.xml file which talks about System.Net.WebException
-<ProblemSignatures>
<EventType>CLR20r3</EventType>
<Parameter0>test.exe</Parameter0>
<Parameter1>1.0.3.33</Parameter1>
<Parameter2>53dca4f6</Parameter2>
<Parameter3>System</Parameter3>
<Parameter4>4.0.30319.18408</Parameter4>
<Parameter5>52311185</Parameter5>
<Parameter6>21b0</Parameter6>
<Parameter7>1fb</Parameter7>
<Parameter8>System.Net.WebException</Parameter8>
</ProblemSignatures>
First run an admin install via command line (cmd.exe) to extract the files from your MSI:
msiexec /a File.msi
Then inspect the extracted files to determine if there are configuration EXE files that perform configuration tasks. Determine what configuration files are there, if any. For example INI or XML files. Check for per user / user profile files.
In case you don't have the tool to view the MSI file, get hold of Orca or install a trial version of a commercial packaging tool. You will need this to see what is happening inside the MSI file. If you list the content of the Custom Action table there may be clues there as to what is going on. Also look in the Registry table for per user data to go into the registry. Debugging an MSI properly takes a lot of domain knowledge, but looking through it like this is useful too. Just post follow-up questions. I assume you have the Wix source code too?
To debug the application launch use Process Monitor (procmon.exe) to determine what is going on during the successful launch. The logging is a bit verbose, but with flags you will get to narrow it down.
- For native applications (Win32, or non-.net), I like to use Dependency Walker (depends.exe) too. It can be used for .NET too, but I find it less useful. I am not aware what the best dependency scanner for .NET is at the moment.
If manual debugging fails, several tools used for application repackaging are able to scan the system and determine the state before and after something is done and capture it as a list of differences. Advanced Installer's trial version should be able to do this. With some technical insight you should be able to identify what is needed from the diff image.
The .msi file is the installation set-up it include the installation script and the actual executable .exe file and other required dlls and configuration files.
I think the issue is with how the set-up is created. when you start the application after installation it is not performing the start up tasks like configuration of environment.
And the when you run the .exe it takes care of these configruations by it self.
I suggest that the testing of setup files .msi files and its generation scripts should be revisited.

Web site references a console app which uses NHibernate to talk to database

I've written a console app which basically downloads an XML file, manipulates it and puts the data into a database. This app uses NHibernate and MindScapes NHibernate designer tool. Which works fine when I run it as a stand alone thing.
Now I want to create an MVC website and when a certain button is clicked on that website, I want it to trigger the console app to download the appropriate xml file and do its thing.
I get an error:
Could not find file
'C:\Dev\WagerWatcher\WagerWatcherWeb\bin\hibernate.cfg.xml'.":"C:\Dev\WagerWatcher\WagerWatcherWeb\bin\hibernate.cfg.xml
WagerWatcherWeb is the website, So I think it's looking in the WagerWatcherWeb project for a file which is actually located in the 'WagerWatcher' project.
Is it as simple as changing an app.config file somewhere to redirect to the actual file? and if so, where abouts? I can't fins it to save myself,
Just place (copy) the configuration file (used in your console app) to deployed web-app folder. Read: 3.8. XML Configuration File
An alternative approach is to specify a full configuration in a file named hibernate.cfg.xml. This file can be used as a replacement for the <nhibernate> or <hibernate-configuration> sections of the application configuration file.
While the web application is the "run-time" (just calling the API of your console application) it must be provided with all configuration. Even for referenced libraries...

Categories

Resources