Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include referenced project's .config file

Rather than excluding a file from the referenced output of an assembly, I want to add one!

I have a console application project (BuildTest1) that references a second class library project (ClassLibrary1). The Visual Studio solution looks like this:

Solution layout

I have a class library project that has an app.config. I want this .config file copied to the referring project's output, just like the .dll and .pdb files are. The config file for the class library is copied to the class library output directory as 'ClassLibrary1.dll.config'

I've tried adding this to the .exe project's .csproj file but it doesn't seem to make any difference:

  <PropertyGroup>
    <AllowedReferenceRelatedFileExtensions>
        .pdb;
        .xml;
        .config
    </AllowedReferenceRelatedFileExtensions>
  </PropertyGroup>
like image 813
David Gardiner Avatar asked Mar 19 '12 06:03

David Gardiner


People also ask

What does .config file do?

A configuration file, often shortened to config file, defines the parameters, options, settings and preferences applied to operating systems (OSes), infrastructure devices and applications in an IT context. Software and hardware devices can be profoundly complex, supporting myriad options and parameters.

What is .config file in user?

In computing, configuration files (commonly known simply as config files) are files used to configure the parameters and initial settings for some computer programs. They are used for user applications, server processes and operating system settings.


1 Answers

I was so close... I tracked this down to the MSBuild ResolveAssemblyReference task that is called from the ResolveAssemblyReferences target in Microsoft.Common.targets. This is what populates the ReferenceCopyLocalPaths item.

So looking at the pattern of files it was matching I discovered that the file extension .dll.config (rather than just .config) did the trick:

<PropertyGroup>     <AllowedReferenceRelatedFileExtensions>         .pdb;         .xml;         .dll.config     </AllowedReferenceRelatedFileExtensions> </PropertyGroup> 
like image 139
David Gardiner Avatar answered Oct 18 '22 11:10

David Gardiner