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

Christian Obkircher 6 Reputation points
2021-07-13T20:48:04.913+00:00

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?

Community Center | Not monitored
{count} votes

1 answer

Sort by: Most helpful
  1. PengGe-MSFT 3,381 Reputation points
    2021-07-15T06:27:20.507+00:00

    Hi @Christian Obkircher

    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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.