Include referenced project's .config file

守給你的承諾、 提交于 2019-12-31 08:57:49

问题


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:

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>

回答1:


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>


来源:https://stackoverflow.com/questions/9765686/include-referenced-projects-config-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!