Kor*_*rey 35 app-config production-environment visual-studio
在发布模式下构建时,有没有办法自动使用单独的app.config?
换句话说,我想用一个app.config进行测试,然后用另一个进行测试.
目前,我保留了一个名为app.config.production的单独副本,并在构建发布后手动覆盖bin\Release\Application.exe.config.
Mat*_*u H 19
一个干净的解决方案是将 2 个文件分组为App.Debug.config
,并根据编译时的配置将好的文件更改为:App.Release.config
App.config
App.config
<ItemGroup>
<None Include="App.config" />
<None Include="App.Debug.config">
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.Release.config">
<DependentUpon>App.config</DependentUpon>
</None>
</ItemGroup>
<Target Name="SetAppConfig" BeforeTargets="Compile">
<Copy SourceFiles="App.Debug.config" DestinationFiles="App.config" OverwriteReadOnlyFiles="true" Condition=" '$(Configuration)' == 'Debug' " />
<Copy SourceFiles="App.Release.config" DestinationFiles="App.config" OverwriteReadOnlyFiles="true" Condition=" '$(Configuration)' == 'Release' " />
</Target>
Run Code Online (Sandbox Code Playgroud)
使用此解决方案,您将在 Visual Studio 中得到类似以下内容:
tru*_*oda 16
通过contet菜单卸载解决方案资源管理器中的项目.编辑.csproj文件.将此字符串添加到文件中.
<PropertyGroup>
<AppConfig>App.$(Configuration).config</AppConfig>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
ne1*_*10s 15
我最近发布了对类似SO主题的极其迟来的回应:https: //stackoverflow.com/a/27546685/2798367
为清楚起见,我将在此重复一遍:
这对派对来说有些晚了,但我偶然发现了一种实现文件web.transform
方法的好方法app.config
.(即它使用命名空间http://schemas.microsoft.com/XML-Document-Transform
)
我认为这很"好",因为它是纯xml方法,不需要第三方软件.
根据您的各种构建配置,父/默认App.config文件来自.这些后代只会覆盖他们需要的东西.在我看来,这比必须保持x
完整复制的配置文件数量要复杂得多,比如在其他答案中.
这里发布了一个演练:http://mitasoft.wordpress.com/2011/09/28/multipleappconfig/
看,妈妈 - 我的IDE中没有明确的构建后事件!
一种简单快捷的方法是创建第二个文件"App.release.config"并插入此预构建事件:
IF $(ConfigurationName) == Release COPY /Y "$(ProjectDir)App.config" "$(ProjectDir)App.debug.config"
IF $(ConfigurationName) == Release COPY /Y "$(ProjectDir)App.release.config" "$(ProjectDir)App.config"
Run Code Online (Sandbox Code Playgroud)
这个帖子构建事件:
IF $(ConfigurationName) == Release COPY /Y "$(ProjectDir)App.debug.config" "$(ProjectDir)App.config"
Run Code Online (Sandbox Code Playgroud)
这可能有点奇怪,但它将允许您继续使用.Settings
文件作为调试设置,仍然链接到App.config
.的App.release.config
必须是手工打造的,但它很容易切换此功能.
与最佳答案类似,但通过这种方法,如果愿意,您可以看到实际文件,并且智能感知不会在 csproj 文件中抱怨:
<Target Name="SetAppConfig" BeforeTargets="Compile">
<Copy SourceFiles="debug.config" DestinationFiles="app.config" OverwriteReadOnlyFiles="true" Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " />
<Copy SourceFiles="release.config" DestinationFiles="app.config" OverwriteReadOnlyFiles="true" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
</Target>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
34666 次 |
最近记录: |