question

ChristianObkircher-8181 avatar image
0 Votes"
ChristianObkircher-8181 asked PengGe-MSFT commented

How to deploy a dependency's dll.config file with ClickOnce

My projectA published via ClickOnce depends on projectB. I need the projectB.dll.config file for projectA to work. While MSBuild copies over projectB.dll.config to projectA/bin/ConfigXY correctly, it is not published. VisualStudio (2017) doesn't even show the file in Application->Publish->Application Files.

As a workaround, I added this to A.csproj:

 <Content Include="..\projectB\App.config"> 
   <Link>projectB.dll.config</Link> 
   <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 
 </Content>

I think this is quite hacky, as it wouldn't work if projectB would use transformations, like projectA does. And it is not possible to do this directly in VisualStudio.

Why does MSBuild copy over the file correctly for build, but then doesn't publish it?
And what would be the best workaround?

vs-msbuild
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, @ChristianObkircher-8181
could you share me detailed steps to reproduce your issue on my side?

0 Votes 0 ·

Thank you for your response, @PengGe-MSFT
I created a demo application here: https://github.com/chrbkr/PublishIssueDemo

If you execute it from VisualStudio, or if you build it and execute ProjectA.exe, it works fine: It shows "Hello", and if you click on "ShowEndpoint", it shows "https://localhost/servicemanager/1" instead of "Hello".

However, if you publish the project and execute ProjectA.application, initially it looks the same. But once you click the button, it crashes - the reason being that ProjectB.dll.config is not deployed. It is, however, copied to ProjectA\bin\Release correctly.

0 Votes 0 ·

1 Answer

PengGe-MSFT avatar image
0 Votes"
PengGe-MSFT answered PengGe-MSFT commented

Hi @ChristianObkircher-8181

Welcome to Microsoft Q&A!

Your application want to get url from the config file of project B and replace "hello", right?

I got some information after researching this issue.

You should not add a config file to class library project (Project B).
You need to declare the assemblies' configuration sections in the app.config of your application (Project A) and define a value for a particular number of settings defined in the proper assembly settings.

Create an app.config within the class library project, it contains some configurations and settings, but these configurations and settings will not be used by the executable application calling the library.

You can try to copy these settings from the library config file into the app.config of the caller.
You can also try to create a XML file to copy configurations and settings, make your class library read this file using System.XML instead of System.Configuration.

Sincerely,
Peng


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

In my real-world project, the config file is created automatically, since ProjectB consumes a WSDL contract. The corresponding SOAP service is updated every 6 months by a 3rd party. I want to keep the responsibility to deal with this inside ProjectB, since this library is used by multiple projects.

If the class library config file shouldn't be used by other projects, why is it copied over by default? See this closed issue in msbuild.

What's also interesting is that if I add a user section and access a setting in it via Settings.Default.MySetting, the ProjectB.dll.config file is still missing, but I can somehow still read that setting from ProjectA? Are the settings somehow imported during build, and the reason my application doesn't work is that I try to access them via ConfigurationManager.OpenExeConfiguration(GetType().Assembly.Location);?


0 Votes 0 ·
PengGe-MSFT avatar image PengGe-MSFT ChristianObkircher-8181 ·

Hi @ChristianObkircher-8181
I have searched and read many similar threads, and all the answers I can find cannot solve your issue.
About ConfigurationManager, you can refer to this document.
I suggest you can start a new thread and report this issue to VS Product Team in our Developer Community with some reproduced or detailed information. if you do report this issue, please share the link here, other forum members, include me, who are interested or meet the same or similar issue can go to vote for this thread.


0 Votes 0 ·