the*_*man 9 .net c# msbuild app-config visual-studio
我有一个由许多其他Web应用程序项目引用的类库.它有许多app.config
我希望在所有引用Web项目中使用的设置.构建类库时,它会将其复制app.config
到自己的bin
文件夹中<assembly.name>.dll.config
.
<assembly.name>.dll.config
其复制到每个引用Web应用程序项目的bin文件夹中?Copy to Output Directory
或Build Action
(以任何组合)不起作用.暂且不说:在每个Web应用程序项目中手动放置所有这些配置是不切实际的.我可以通过<assembly.name>.dll.config
在bin文件夹中查找来读取文件,并从那里提取设置.我已经可以做到这一点,所以这不是问题 - 我只需要确保文件将在那里阅读
the*_*man 13
通过将以下内容添加到类库的项目文件中,可以在没有第三方工具的情况下实现此目的assembly.name.csproj
:
// Find this <Import> element for Microsoft.CSharp.targets
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
// Add this <ItemGroup> element immediately after
<ItemGroup>
<Content Include="app.config">
<Link>$(TargetName).dll.config</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
这会导致将app.config
其复制到引用它的项目中<assembly.name>.dll.config
.这很好,因为您只需配置一个.csproj
文件,效果就会级联到所有引用项目.
归档时间: |
|
查看次数: |
4382 次 |
最近记录: |