23

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>
Community
  • 1
  • 1
David Gardiner
  • 16,892
  • 20
  • 80
  • 117

1 Answers1

38

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>
David Gardiner
  • 16,892
  • 20
  • 80
  • 117
  • 3
    Thanks for the followup. Too bad you can't configure it the other way around, from the library project as that's the one that would know that others need its config file. "You want my config file, trust me" – Greg Biles Aug 14 '13 at 13:04
  • 3
    Maybe it is obvious but to add a config file for an executable file one must add "exe.config", when having for instance a reference to a console application. – polkduran Jun 16 '15 at 16:49
  • 2
    Man, you saved my day :) – Xavi Ivars Nov 27 '15 at 10:00
  • This is awesome. So glad I don't have to put in some manual copy step in the build process. Thank you! :D – BrainSlugs83 Jan 28 '16 at 05:35
  • Thanks so much for this answer. Saved me a lot of time and effort. In my context, it was used to run VStests of a test project as part of the TFS/RM build and deploy process. – vandsh Sep 13 '16 at 14:30
  • This is N E A T ! – shekhar Feb 03 '17 at 19:44