I have deployed an app that downloads from a web server. This is a normal desktop app installed using a msi produced by Visual Studio setup project. The address of the server is stored in app.exe.config as an application setting. Later, I change the address in app.exe.config using notepad, but the app is still using the old web address. In fact, I tried deleting the app.exe.config and the app still managed to get the old web address?????
Can someone explain what is happening.
Sorry if it confused some people. The settings are managed using the C# project's properties -> Settings page. The project is called updatesdownloader and the actual file I edit is updatesdownloader.exe.config which is in the same folder as the exe.
The code I used to read the server address string is:
Server updateServer = new Server(new Uri(UpdatesDownloader.Properties.Settings.Default.Server));
Where is the file that you are changing? Is the setting a user setting or an application setting?
You may want to look for your settings in the %AppData% or %ProgramData% folders on the user's machines.
You need to us ConfigurationManager.RefreshSection for a custom section that contains your settings.
Check this for an example on how to create a custom section
Are you sure the address is not hard-coded in the app itself? I would be sure that if you made reference to a URL using ConfigurationManager.AppSettings["SomeUrl"]; and attempted to go there, it would fail if the file did not exist.
Related
I am trying to help port a .Net service to a more modern .Net version (possibly Core) and use the MSIX installer. The application has several configuration files generated by the compiler (in source they are app.config but compiled they become *.exe.xml), they are installed into Program File right next to the binaries and a GUI helper app as well and the application itself can modify them to change service behavior (port, ip, tls cert, etc).
Writes under C:\Program Files\WindowsApps\package_name are not allowed.Writes under C:\Program Files\WindowsApps\package_name are not allowed.
The problem I am facing is that the MSIX installer makes it so that files in it's sandboxed version of Program Files cannot be written to (see above). That means that this application cannot be configured, so I am trying to figure out not only how to make the app configurable again, but also how windows wants to handle app configuration.
Right now it seems like there is two general approaches to do this:
write the configuration data to the service account's AppData/local folder
try to mimic a /etc/Myservice behavior in another folder. (meaning a local system-wide directory that houses configuration data for the service)
If you suggest #1 please answer the following additional questions:
How would I move Application configuration files to a user configuration file directory
how can an admin with a normal account modify the config file in the Service Account's AppData folder with the mentioned GUI helper application? (do they need to enable desktop access to the service account, login and run the GUI)?
If you suggest #2:
Where would you suggest this directory exist (specifically where will MSIX allow it)?
How do I tell the .Net application that the files are not right next to it? Can I just use AppData.CurrentDomain.SetData?
Well, a service running on the system account is the same for all users, so I would say that CommonApplicationData is a better folder for storing its settings, instead of appdata. This folder is easily accessible to both your service and to any admin that needs to deploy a custom config file.
In AppData you should store only actual user files (like files or settings generated by the actions taken inside your app by a specific user - thus different files for different users).
Now, the second part is where you need to configure you code to load the config file from a custom path instead of looking for it next to the EXE. I am no .NET expert but after a quick search I found this:
Relocating app.config file to a custom path
The modern approach to deploying app customizations
What is not clear to me is how your customers use the GUI helper tool to customize the config file. Is this just a tool that is used by someone from the IT department to generate the config file, and then they would copy that file and deploy it to the end-user machines using an MSI/MST file (or through some other custom deployment method)?
If your application is only deployed by IT folks, then you can try another simpler (and much elegant) solution for providing it with a custom config file, which actually doesn't require any code changes.
You can still leave the config file next to the EXE, in ProgramFiles and instruct the IT teams that deploy the app to use an MSIX Modification Package to deploy the custom config file generated by your GUI helper. (check the link included above for an example - with a video version at the end of the article).
Note: IT teams can use multiple free or paid tools to generate MSIX Modifications Packages.
Of course, your GUI helper tool still needs to generate that customized config file in a folder where it is allowed, as it can no longer write under ProgramFiles. So actually, you do need to modify a little bit your code in this scenario too.
I have written a C# app using Winforms, and am trying to utilise the inbuilt Properties.Settings (User scope) to remember user state between launches of the program.
When the app is deployed via Visual Studio's inbuilt Build > Publish, apparently this file is put into the Local Appdata folder.
However, I want to use NSIS to create the executable of the program. I am able to place the ProgramName.exe.config file into Local AppData, via NSIS script, but my app does not seem to read from it. No user settings persist.
Is this even possible? Or should I use my own method (database or write my own settings xml) to store user settings?
OK, I got it working with NSIS.
The App.config file has a property called "Copy to Output Directory" which was set to "Do not Copy" by default. I found this information here: https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/
I found out where the user.config file was going to be created, with help from #Jimi by adding System.Configuration as a reference, and then getting the path using:
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
The user.config file is not created on application install, rather the first time that the following is called:
Properties.Settings.Default.Save();
There is nothing special that the developer has to do in NSIS.
I just finished my simple C# desktop application. What I want to provide to my customer is an installer of the application(.exe). Also, I want the app to check for updates if ever I will do some updates without giving my customer the installer again.
I have read about the "ClickOnce" but I find it confusing especially the FTP part. Do I need to have an FTP server to upload the application files? Aside from that, most of the tutorials are deploying in the local machine (I guess).
Please advise me on this one.
You can use a tool like Advanced Installer. It is free and easy to use. But if you want to do automatic updates you can purchase a license for the professional version.
A direct quotation from MS documentation:
To specify a publishing location
With a project selected in Solution Explorer, on the Project menu, click Properties.
Click the Publish tab.
In the Publish Location field, enter the publishing location by using one of the > following formats:
To publish to a file share or disk path, enter the path by using either a UNC path (\\Server\ApplicationName) or a file path (C:\Deploy\ApplicationName).
To publish to an FTP server, enter the path using the format ftp://ftp.microsoft.com/.
Note that text must be present in the Publishing Location box in order for the Browse (...) button to work.
For more information please check the following link.
Long story short, you can just use a publicly accessible file share on the intranet. Using an FTP server is just an alternative.
I've created an application which is connected to database and I want to have Installer which allows me to run my app on other PC. I've tried publishing, creating Setup File in Visual Studio and Advanced Installer, but none of this options works. When i run it on my computer it works perfect. I know that i have to change connection string when i connect to database on other PC. I have SQL Server and .NET Framework on other PC too so it's not the problem. I searched and tried many solutions on the internet, please help me !
You can always include any type of file inside a Setup Project in Visual Studio. However, if you want to make a custom installer, you can easily do that.Here's some guidance that will help you greatly :
1.Create a zip
Search the term on google adding a c# tag at the end. You will find numerous answers even on SO on this. You can create a zip file and include every related file to your project in it. You can also simply add the database file in resource and access it.
2.Create the setup application
Create a WPF/WinForm project, design it the way you want. Now embed the earlier created zip file as a resource. Create a button to extract the zip file(do a quick google search of it too). You will now have a fully-customized installer
3.Take the installer to next step
What if there's already a version of your app installed on the client machine ? In your customized installer, make sure to create a registry key which will hold the path of where the installer will install the app(I mean where it will extract the .zip). Also add a check for the registry value. If there's a registry value, get the value which will be the path of the previously installed version, use the path to delete the folder/directory. Now do the rest of the work of step 2
The quickest way
Embed the database in your app as a resource.Now your setup project will automatically include it. However, the problem is that you cannot access the file directly from the resource as it has to be attached with a SQL Instance. However, you can use SqlLite for this.
Hope this helps :)
I have installed a C# Windows Service on Windows Server 2008. I installed it with InstallUtil. The service reads some data from the app.config file and it is doing it fine. Can you tell me where this file is located after installing the service?
I have been looking for hours but can't find it.
You can verify the exact location of the installed Windows Service by following the steps below:
Bring up the list of Windows Services by clicking the "Services" icon under the "Administrative Tools" icon. You can also get this list by typing "View local services" in the Search Menu under the Start Menu.
Select your Windows service in the list of installed services, right-click and then select Properties. You can also double click on row representing the service.
Locate the "Path to executable" value on the Properties dialog box. The value will include any command line parameters.
Open the folder in which the service executable resides.
If the Windows service has been built with .NET Framework, its configuration will be stored in the corresponding .config file, i.e., the name of the executable suffixed by ".config", e.g., if the name of the executable is "XyzService.exe", then the name of the .config file will be "XyzService.exe.config".
A couple of things to note:
If you installed the service after building it on the same machine using say, Visual Studio, then Visual Studio would have transformed the App.config file from the project and placed it in the build output folder automatically (and renamed it appropriately using the above naming convention).
If your machine is set to hide file extensions in Windows Explorer, you will see 2 files "XyzService" and "XyzService.exe". In this case, the "XyzService.exe" is your config file. If you then switch off the option to hide file extenions in Windows Explorer, you will then begin to see "XyzService.exe" and "XyzService.exe.config".
If you cannot find a corresponding .exe.config file, then it is possible that the code within the service is falling back to default values. In this case, you can place a properly named and formatted config file alongside the service executable and then restart the service and everything should be fine.
According to Microsoft
For client executables, the application configuration file resides in
the same directory as the application's executable and has the same
base name as the executable with a .config extension.
Note, if your exe is called appname.exe, and you have Windows explorer set to hide extensions, then your application will display as appname and your config file then it will be displayed as appname.exe (even though the true name is appname.exe.config)
As others have pointed out, InstallUtil doesn't do anything with the config file and it should have copied to the server in the same manner as the exe itself.
It is the same location from where you have registered service using installutil tool.
The App.config is likely called {ProjectName}.exe.config given the fact that it is a Windows Service. Check to see if that file exists and is what you are looking for.
The same place where your application (Windows Service) is.
Check it out, if it's not there place it in the same directory as of service.
If you have a live environment (and from your question it seems like you do), you can check what's actually happening using the superior Process Monitor utility. But usually the .config fileis located right next to the .exe, and named the same.