【问题标题】:Exclude web.config from TFS-GIT with Visual Studio使用 Visual Studio 从 TFS-GIT 中排除 web.config
【发布时间】:2015-04-02 00:19:43
【问题描述】:

我们正在从 TFS 迁移到 TFS-GIT。以前,我们设置了三个不同的分支(dev、qa、prod),每个分支都有自己的 web.config。当我们对 web.config 进行更改时,我们会手动将它们向上移动并强制它们不要合并。现在我们正在迁移到 GIT,我们已经开始使用 web.base.config,然后使用配置文件和转换为我们想要的环境配置它。

总的来说,这很好用,但是每次我们尝试提交时都会看到 web.config 已被修改,我们要么需要手动撤消它,要么需要处理潜在的合并冲突。我尝试从 GIT 中删除它,将其添加到 git ignore,然后从源代码管理中删除它,但随后 Visual Studio 抱怨未启用调试,将 web.config 重新添加到项目中并将其重新添加到吉特。

我觉得有更好的方法。有没有人遇到过类似的用法并想出解决方法?

【问题讨论】:

  • 我对你的问题有点不清楚......为什么git ignore 在这种情况下不起作用?......就像你不会检查 web.config 和克隆这个 repo 的人一样, VS 会自动生成它...
  • Visual Studio 重新添加覆盖 .gitignore 的文件。在这种特定情况下,如果有人尝试调试,他们会收到一个错误,即调试未启用,因为尽管 web.config 存在,但解决方案中并未包含它。如果他们从调试开始,它会将其添加到项目文件中,并通过扩展强制将其添加到 git 中。

标签: git visual-studio visual-studio-2013 tfs


【解决方案1】:

我们找到了适合我们需求的解决方法。

首先,我们将 appSettings 和 connectionStrings 配置片段从 web.config 移出到名为 web.appSettings.config 和 web.connections.config 的文件中。这些文件都没有包含在项目文件中,也没有添加到源代码管理中。

<appSettings file="web.AppSettings.Config" />
<connectionStrings configSource="web.Connections.Config" />

接下来,我们创建了定义基线配置选项的 web.AppSettings.base.config 和 web.Connections.base.config。我们还为每个构建配置文件(debug、qa、release)创建了一个文件。所有这些文件都包含在源代码管理和项目文件中。

最后,我们添加一个 pre-build 事件来转换 web.AppSettings.base.config,使用 web.AppSettings.[build profile].config 来创建 web.AppSettings.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>

这实现了我们的所有目标。我们能够快速更改我们所指向的环境,并且我们能够避免需要不断提交和合并不断变化的配置文件。此外,为了使其易于管理,我们标记了相互依赖的各种配置文件,以使它们显示为 hierarchy in solution explorer,只需在项目文件中进行简单修复。

<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>

【讨论】:

    猜你喜欢
    • 2017-02-13
    • 2015-07-13
    • 2014-05-13
    • 1970-01-01
    • 2017-07-31
    • 2014-06-06
    • 2016-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多