app.exe.config file not published with ClickOnce application - c#

I have a clickonce app that needs the app.config file deployed.
In Visual Studio, if I right click on the app.config file and select properties then change the Build Action to Content, the app.config.deploy file gets created, but there is no app.exe.config.deploy file.
I really don't even need the app.exe.config.deploy file and I don't know why Visual Studio (2010) includes it.
At this point, I click on the properties for the clickonce .csproj file, click on the publish tab and click on Application Files. "app.config" and "app.exe.config is set to "Include (auto)". But I don't have the option to disable the app.exe.config.
The reason I need app.config deployed is because I'm using the following code:
var str = ConfigurationManager.AppSettings["oem"];
I'm deploying multiple versions of this with an external build script. The build script swaps out different versions of the app.config for each different published version of the code.
Bottom line question. Is there a way to either:
Get the app.exe.config to deploy with the rest of the publish
Only get the app.config file to deploy (without the app.exe.config)
If I add say a text file to the project and set it's deployment type to "content" as specified above it gets included.

Related

How do I force Visual Studio 2019 to generate a .deploy file for an icon for ClickOnce deployment/install

I'm running into a problem publishing/installing a ClickOnce application being built in C# in Visual Studio 2019. The application is being built using .NET Core 3.1 and WPF.
I have an icon I am using for the application that is included in the project with the filename "loader.ico". The ClickOnce manifest is calling out for loader.ico, but the required Loader.ico.deploy file is not being generated when publishing, which is throwing an exception when trying to run the setup.exe to install the application to a client PC (actual filepaths have been replaced with [Path]:
+ Downloading file:///[Path]/x64/ClickOnce/Application Files/.NET Bootloader_1_0_0_4/loader.ico.deploy did not succeed.
+ Could not find file '[Path]\x64\ClickOnce\Application Files\.NET Bootloader_1_0_0_4\loader.ico.deploy'.
I have attempted a few things using what information on the problem I could find:
I set the Build Action for loader.ico to Content and set Copy to Output Directory to Copy Always. I also set the "Settings>Application Files" setting for loader.ico to Include. This has no effect on the resulting Publish, and no loader.ico.deploy file is generated.
I also receive the following in the output window when publishing:
Unable to apply publish properties for item "loader.ico"
I have also tried excluding loader.ico from the "Application Files", but this does not remove the reference in the .manifest file.
So now I am at a bit of a loss. I don't know why it would demand a .deploy file for the icon (I'd think it would just be embedded? No need for a separate icon file?). I can't seem to get the ClickOnce publishing process to generate the required loader.ico.deploy file, and I can't seem to get the manifest to remove the reference to it. What settings could be used to force the generation of this .deploy file (or force the manifest to not reference it)?
I had the same problem your application .ico file causes this error so you have to change its properties setting to Build Action: Content and Copy To Output Directory: Copy always.
hope it works
I can confirm from my very own experience how frustrating this is. I have tried anything and everything.
For the time being - until this issue is sorted - I am suggesting that you manually add the .ico file to the Apllication_1_0_0_x folder and appending '.deploy' at the very end.
So file will look like 'my-icon.ico.deploy'.
It works. Tried and tested.
In my case it helped:
Publish -> Show all (Settings current project) -> Settings -> Application Files -> (Show all files):
Find ico file, select publish status to Include | (Required) | Include.
From now on, the ICO file will be added when publishing
Additionally to the icon loading problem that I initially "solved" with Avrohom's method, I faced some issue with WebView2 not working / being loaded.
Both of these problems stopped when I disabled the click once publishing profile (.pubxml) option for producing a single EXE file:
<PublishSingleFile>False</PublishSingleFile>
Tested with .NET6, Visual Studio 2022

ClickOnce deployed application can't find external DLL

I have this WinForms application that uses an external dll file (Winppla.dll) so I can print tags in my Argox printer. Since I cannot add the dll file as a reference to the project, I use the command [DllImport("Winppla.dll")] on my class.
When I run the project in Visual Studio, it works perfectly.
Then I published my application using ClickOnce and when I try to run the application, I get the message error saying that the Winppla.dll could not be found, even though I am running it on my machine.
I tried to:
copy the file to the bin folder of the project before publishing
copy the file to the packages folder of the application before publishing
copy the file to the latest version folder on the Application Files folder (on the publishing location of the application)
add the file as a resource on the project
add a folder with the file as a Reference Path on the project
but none of these worked.
This project also uses SAP CrystalReports, and it works just fine.
Any ideas about how to make it work?
Following #Bearcat9425 instructions in the comments section of the question, I finally solved the problem:
Copy the file to the project folder and include it on the project
(on Solution Explorer, click on 'Show All Files', then right-click in the file and select 'Include In Project')
Mark the file as one of the application files on my publish tab
(right-click on my project and select 'Properties', then go to Publish tab and click on 'Application Files' and make sure the Winppla.dll is marked as 'Include')
Copy the Winppla.dll file to a shared folder in our server (I placed it on the same folder where I placed the setup of my application)
On each DllImport command write the complete path to the file shared location: [DllImport(#"\\the-path-on-the-server\Winppla.dll")]
Publish!

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

Deploy different WCF .svc files based on configuration

I have a Service1.svc file that is a normal WCF service. If I deploy the WCF project it will happily copy the Service1.svc file along with the binaries and the other files. So far, so good. What I want is, based on the selected build configuration, or some other trick, to publish different contents for the Service1.svc file.
Let's say I have a Service1.Conf1.svc file and a Service1.Conf2.svc file and two configurations (like Debug or Release) that are named Conf1 and Conf2. When I click publish and have the Conf1 configuration selected, I want the publish folder to have a virtually created Service1.svc file whose contents are from Service1.Conf1.svc. When I click publish and have the Conf2 configuration selected, I want the publish folder to have a virtually created Service1.svc file whose contents are from Service1.Conf2.svc.
I would like to have this for the publish action, not the build action (which could be achievable by a post-build or pre-build event). The main purpose is to adjust the contents of the Service1.svc file according to the publish environment.
Any ideas?
We took a different approach and generate all required config/svc files for all possible installs (using TT file generation) and let the installer copy the correct configs/svc files (based on user selection during install).
The names of the files are constructed by inserting the target platform name into the standard name e.g web.local.config, web.dev.config, web.test.config etc
This way you can give one installer to anyone from any department. They just choose the platform.

Loading app.config file in Release

In my Visual studio 2008 project, I've added app.config file where I store some app-data in xml format.
I read this data in code like this:
string somedata = ConfigurationSettings.AppSettings["somedatakey"].ToString();
when I start application in Visual studio, it works. But if I try to run the exe file (release or debug) I get error (if i debuf it it breaks on the line above):
Object reference not set to an
instance of an object.
The file app.config is not inside folder.
Is the app.config file in the same folder as your exe? If not, copy it there.
Starting debugging in visual studio builds everything, and copies the output (including app.config) to the output folder, starting it from there.
#Jullin: When you run project from visual studio editor by pressing F5 then CLR pick app.config file to read data but when you want to run project from .exe (bin/debug or bin/release) then clr read applicationName.exe.config, which you must have within your debug or release or any folder from where you access you applicationName.exe.
Like i have a window application named "WindowsFormApplication", when i build it successfully in release folder i have WindowsFormApplication.exe and WindowsFormApplication.exe.config and some other files. so make sure you release project successfully and your release folder must contain files.
While Running in from the Exe make sure that u have added app.config should be in the same directory

Categories

Resources