I'm deploying an application using ClickOnce, the problem is that the configuration file (xxx.exe.config) is not embedded in the package and there is no option to include it. Another problem with the config is that When I'm trying to manually write it to the directory where it is delopyed (Environment.CurrentDirectory) I'm getting an exception - I have no permissions to do that.
Any ideas on how to deploy the app along with the configuration file? (and to make it writable, because the applications during ti's runtime alters the config values.)
Thanks in advance
You can also change build action for files that you want to include in ClickOnce deploy: Properties for a file → Build Action → set to "Content", this will add the file to the list of Application files in Publish project options.
If you need to publish a file from a referenced project, I didn't find a better solution rather than to Add → Existing Item → On "Add" button, select "Add as Link", then set action to Content and check the list of published files.
The config file should get published automatically; if not, ensure that it is configured to copy to output, and (if that fails) check the publish files (project properties -> publish -> application files; the config file should be marked as "include (auto)" or "include").
You shouldn't attempt to update anything in the app install directory. That is a bad idea generally (since you can't assume you can update "program files" unless you're an admin), but the same holds true for ClickOnce too.
Just create a settings file with some user settings; these will be saved in the user's profile, so can be updated reliably. You can't edit the files deployed via ClickOnce; even if you had access, it would (by default) break the hashing function, and it will refuse to load them. You can turn off the hashing, but... this still isn't a great idea.
When you click on the Properties of your project and go to the Publish tab of the project's properties, click Application Files... then check the 'Show All Files' checkbox. You should see an option to choose your applications config file from there.
In my experience the <*>.exe.config file is usually set to include automatically however.
Related
I have a WPF project that is now finished, and I want to publish the app into an installer that other people can use.
When I publish the project, the project compiles into setup.exe, but on install the folders that I have do not get included.
I've been reading the guides, and made sure to include the files inside the folders as Content or a Resource. I've also made sure they are always copied. When some of my files are copied, they have a .deploy extension, and I need it to be an .xml in order for some function to read them. Images that I have in the app load fine however.
What do I need to do to have my custom files be EXACTlY as they are, xml as xml, txt as txt and so on. Also I have some empty folders, like this TempCF that I use at some point. Do i need to create it via code?
If you go to Project->Properties->Publish->Install Mode and Settings->Options->Deployment in Visual Studio, there is a "Use ".deploy" file extension" option that you can untick to get rid of the .deploy extension being added to your published files:
Empty project folders are not included in the output. Either put a dummy content file in them or create the folder dynamically as needed during runtime.
# Nikola L.
You could try to use the following methods to add the files in your program to the installation package so that you can have the files you need in your installation path. If I misunderstood your question, please let me know.
The steps are as follows:
1.Right-click on the Setup project and select View -> File System
2.In the File System page, right-click the Application Folder (File System on target Machine) and select Add->Folder(named User's Application Data ) -> File…-> find the file under your project and select the file you need.
Such as:
3.Right-click the Setup project.
Install your setup package.
You can find the files you added in your installation path.
The result is like the picture below:
I'm trying to create a WPF application to do some of the time consuming QA tasks easier. Now I ran into problem of creating a file that would be used for configuration of some operation via ssh. This file will contain default configuration, however it might be updated by the user with new values.
I changed the properties of a file to "Build Action - Content" and "Copy to Output Directory - Always" however when I publish and install the application the file is not in the directory.
How can I make the file appear in the output directory and be available for some changes?
The published files get a .deploy extension by default. This is a setting that can be changed under Project->Publish->Options->Deployment in Visual Studio.
If you uncheck the Use ".deploy" file extension option and re-publish, you should see and be able to use the content file in the Application Files/app directory of the output folder.
Consider these two software: MyGame.exe and SocketTest.exe.
MyGame.exe doesn't depend on any files to run but SocketTest.exe is an actual software. It can only run if one or more of four other files are in the same folder as itself. These files are: metouia.jar, SocketTest.bat, SocketTest.jar, SocketTest.sh
I want to create a software using Windows Form in Microsoft Visual Studio using C#. It will have two buttons: "Launch MyGame" and "Launch SocketTest."
I go to the Solution Explorer tab and right-click my .csproj file to click Add Existing Item... so I can add MyGame.exe, SocketTest.exe and the other four files into the Solution Explorer.
For the File Properties of the 6 files, under "Copy to Output Directory" I choose "Copy Always."
For Build Action, I'm not sure. I use "None". My buttons can still launch the two .exe files.
However, I'm not sure which settings to use if I want other computers to be able to launch those .exe files with my software, especially for the .exe file that depends on other files. I've read the Build Action descriptions (online too) but still can't decide on the proper one for my situation.
The way your're doing it is fine. A few notes:
Instead of "Copy Always", you can use "Copy only if newer"
For "Add Existing Item...", instead of adding the items directly, you can pull down the "Add" button and select "Add link" - this will keep the files in sync with the source items, in case they are updated
Build action "none" is correct. You are not building these items, just copying them to your output folder.
Whatever you do with your project -- publish, deploy, etc -- the added items will stay with your project output.
Good luck!
Rather than adding artefacts into your launcher which just produce noise as far as the .csproj is concerned, consider using build events.
Right click your launcher's project, choose Properties then Build Events. In the Post-build event command line enter appropriate copy commands to copy your binaries and artefacts from your other project folders to your launcher's OutDir folder.
Anything more and you should probably look into making an installer.
I want to save some settings on a config file for future use.
I'm trying to use the regular code that I see on all the tutorials -
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["username"].Value = m_strUserName;
// I also tried -
//config.AppSettings.Settings.Remove("username");
//config.AppSettings.Settings.Add("username", m_strUserName);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
Now - I can see that on runtime - the file "...vshost.exe.config" on "Debug" folder is changes, nut when I close my application - all the changes are deleted.
What can I do?
To test using the normal exe's config file un-check the box for "Enable the Visual Studio Hosting Process" in the "Debug" tab in the project properties menu. That will make visual studio no-longer use the vshost.exe file to launch and the correct config file will be used.
When you deploy your application to your end users, there is no vshost.config.
Your changes will be applied to the real exe.config. So you don't have to worry for this.
When you build your application in a debug session, the app.config file, present in your project, gets copied over to the output directory. Then this config file gets copied to vshost.config as well. In this way the contents of app.config overwrites any changes made during a debug session in the vshost.exe.config.
However let me say that writing this kind of information into an application config is a bad practice. The configuration file should be used only to store permanent configuration that usually don't change during the lifetime of your application. Connection settings, for example, are valid info to store there because you normally don't change these and you don't want to hard code them.
Settings like the user name should use user.config instead. This config is per-user/per-app and allows read/write access.
I am creating an installer for my C# application, and I want to put a link to the configuration file into the start menu, so that users can open it for editing in notepad from the program folder in the start menu.
I seem not to be able to put a link to it however - does anyone know how to do this? (Really, I would just love to put "[targetdir]\myapp.exe.config but VS doesn't let me edit the field, only select from a file browser).
Many thanks,
Rob
I found the solution and it's pretty easy:
Add Project Output for your project in the setup project
Select Project Output from File System in left pane and go to the properties of the project output. Then add a filter *.config to remove the .config file from your project output.
Rename the app.config from your actual project to the output name that your App exe ([ProductName]) will have along with the config extension ofcourse.
Add the [ProductName].config to your setup project as a File.
Create a Shortcut to that file and add it in any setup folder desktop or program folder.
Voila.
You're all set.
Isn't the config file added in your installer? You should be able to select it when prompted for the shortcut target (the "Select Item in Project" dialog). Please note that in this prompt dialog you first need to browse to the folder which contains it (for example double-click "Application Folder").
If the config file is not added, you need to manually add it in "Application Folder". Only then you can create a shortcut to it.
Please note that Visual Studio doesn't support shortcuts to a specific file from a project output which generates multiple files. In this case you can try using a custom action which creates the shortcut through custom code.
I remember doing it in Vs2005 using as below:
File System Editor > Users Programs Menu
Add> Folder
Add file (Say Config file) point it to the its location