【问题标题】:automatically copy a config file from referenced dll自动从引用的 dll 复制配置文件
【发布时间】:2009-09-15 09:29:57
【问题描述】:

我的 VS2005 解决方案中有 2 个项目:Exe.csproj 和 Dll.csproj

Dll.csproj 有一个 app.config

Exe.csproj 有一个对 Dll.csproj 的项目引用

如果我编译 Exe.csproj,那么 Dll.dll 和 Dll.pdb 会自动复制到 Exe/bin/debug,但 Dll.dll.config 不会。

有没有什么方法可以在没有后期构建事件技术的情况下在 Exe/bin/debug 中获取 Dll.dll.config?

【问题讨论】:

    标签: visual-studio msbuild compilation


    【解决方案1】:

    MSBuild 助你一臂之力!

    将以下目标粘贴到您的项目文件中:

     <Target Name="CopyConfig"
            Inputs="@(DetectedConfig)"
            Outputs="@(DetectedConfig->'$(OutDir)%(Filename)%(Extension)')"
            AfterTargets="DetectConfigFiles">
        <Copy SourceFiles="@(DetectedConfig)"
              DestinationFiles="@(DetectedConfig->'$(OutDir)%(Filename)%(Extension)')">
            <Output TaskParameter="CopiedFiles"
                    ItemName="CopiedConfig" />
    
        </Copy>
        <Message Importance="High"
                 Condition="'%(CopiedConfig.FullPath)'!=''"
                 Text="Copied config: %(CopiedConfig.FullPath)" />
    </Target>
    
    <Target Name="DetectConfigFiles" AfterTargets="ResolveAssemblyReferences">
        <ItemGroup>
            <!-- Add .config onto all the assemblies we reference -->
            <PossibleConfig Include="%(ReferencePath.FullPath).config" />
        </ItemGroup>
    
        <!-- Work out which ones actually exist in the file system -->
        <ItemGroup>
            <DetectedConfig Include="@(PossibleConfig)" Condition="Exists('%(PossibleConfig.Identity)')" />
        </ItemGroup>
    </Target>
    

    【讨论】:

      【解决方案2】:

      右键单击文件(Dll.dll.config)并查看其属性。

      将复制到本地设置为真。这会自动将文件放到输出目录中。

      善良,

      丹

      【讨论】:

      • 这将复制到 Dll\bin\debug 但不会复制到 Exe\bin\debug
      猜你喜欢
      • 2018-07-04
      • 1970-01-01
      • 2010-12-05
      • 2015-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-03
      • 2017-11-10
      相关资源
      最近更新 更多