使用Visual Studio从TFS-GIT中排除web.config

使用Visual Studio从TFS-GIT中排除web.config,git,visual-studio,visual-studio-2013,tfs,Git,Visual Studio,Visual Studio 2013,Tfs,我们正在从TFS迁移到TFS-GIT。在此之前,我们设置了三个不同的分支(dev、qa、prod),每个分支都有自己的web.config。当我们对web.config进行更改时,我们会手动将它们上移,并强制它们不合并。现在我们正在迁移到GIT,我们已经开始使用web.base.config,然后使用概要文件和转换为我们想要的环境配置它 总的来说,这非常有效,但是每次我们尝试提交它时,都会看到web.config被修改,我们需要手动撤销它,或者需要处理潜在的合并冲突。我曾尝试从GIT中删除它,将

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

总的来说,这非常有效,但是每次我们尝试提交它时,都会看到web.config被修改,我们需要手动撤销它,或者需要处理潜在的合并冲突。我曾尝试从GIT中删除它,将其添加到GIT忽略,并将其从源代码管理中删除,但visual studio抱怨调试未启用,于是将web.config重新添加到项目中,并将其重新添加到GIT


我觉得有更好的办法。有没有人遇到过类似的iUse并找到了解决方案?

我们找到了一个适合我们需要的解决方案

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

<appSettings file="web.AppSettings.Config" />
<connectionStrings configSource="web.Connections.Config" />
只需在项目文件中进行简单的修复

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

web.config
web.AppSettings.base.config
web.AppSettings.base.config
web.AppSettings.base.config
web.config
web.Connections.base.config
web.Connections.base.config
web.Connections.base.config

我们找到了一个适合我们需要的工作环境

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

<appSettings file="web.AppSettings.Config" />
<connectionStrings configSource="web.Connections.Config" />
只需在项目文件中进行简单的修复

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

web.config
web.AppSettings.base.config
web.AppSettings.base.config
web.AppSettings.base.config
web.config
web.Connections.base.config
web.Connections.base.config
web.Connections.base.config

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