Chr*_* C. 0 git tfs visual-studio visual-studio-2013
我们正在从TFS迁移到TFS-GIT。以前,我们设置了三个不同的分支(dev,qa,prod),每个分支都有自己的web.config。当我们对web.config进行更改时,我们将手动向上移动它们并强制它们不合并。现在我们正在迁移到GIT,我们已经转向使用web.base.config,然后使用配置文件和转换为所需的环境配置它。
总的来说,这很好用,但是每次我们尝试提交时,都会看到web.config已被修改,我们要么需要手动撤消它,要么需要处理潜在的合并冲突。我尝试将其从GIT中删除,将其添加到gitignore中,然后将其从源代码管理中删除,但是Visual Studio抱怨未启用调试,将web.config重新添加到项目中,然后重新添加到GIT。
我觉得有更好的方法。是否有人遇到过类似的问题并想出了解决办法?
我们找到了适合我们需求的解决方案。
首先,我们将appSettings和connectionStrings配置片段从web.config中移出,并移入名为web.appSettings.config和web.connections.config的文件中。这些文件都不包含在项目文件中,并且都未添加到源代码管理中。
<appSettings file="web.AppSettings.Config" />
<connectionStrings configSource="web.Connections.Config" />
Run Code Online (Sandbox Code Playgroud)
接下来,我们创建了web.AppSettings.base.config和web.Connections.base.config,它们定义了基准配置选项。我们还为每个构建配置文件(调试,质量保证,发行版)创建了一个文件。所有这些文件都包含在源代码管理和项目文件中。
最后,我们添加一个预构建事件,以使用web.AppSettings。[build profile] .config转换web.AppSettings.config来转换web.AppSettings.base.config。我们对web.Connections.config做同样的事情。
<Target Name="BeforeBuild">
<TransformXml Source="Web.AppSettings.Base.config" Transform="Web.AppSettings.$(Configuration).config" Destination="Web.AppSettings.config" />
<TransformXml Source="Web.Connections.Base.config" Transform="Web.Connections.$(Configuration).config" Destination="Web.Connections.config" />
</Target>
Run Code Online (Sandbox Code Playgroud)
这实现了我们所有的目标。我们能够快速更改我们要指向的环境,并且能够避免需要不断提交和合并不断变化的配置文件。另外,为了使其易于管理,我们标记了各个相互依赖的配置文件,以使它们在解决方案资源管理器中显示为层次结构,而只需在项目文件中进行简单修复即可。
<Content Include="Web.config" />
<None Include="web.AppSettings.base.config">
<DependentUpon>web.config</DependentUpon>
</None>
<None Include="web.AppSettings.dev.config">
<DependentUpon>web.AppSettings.base.config</DependentUpon>
</None>
<None Include="web.AppSettings.qa.config">
<DependentUpon>web.AppSettings.base.config</DependentUpon>
</None>
<None Include="web.AppSettings.release.config">
<DependentUpon>web.AppSettings.base.config</DependentUpon>
</None>
<None Include="web.Connections.base.config">
<DependentUpon>web.config</DependentUpon>
</None>
<None Include="web.Connections.dev.config">
<DependentUpon>web.Connections.base.config</DependentUpon>
</None>
<None Include="web.Connections.qa.config">
<DependentUpon>web.Connections.base.config</DependentUpon>
</None>
<None Include="web.Connections.release.config">
<DependentUpon>web.Connections.base.config</DependentUpon>
</None>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1770 次 |
| 最近记录: |