【问题标题】:TFS Build fails with "cannot access file *FakeTypesCache"TFS 构建失败并显示“无法访问文件 *FakeTypesCache”
【发布时间】:2016-11-03 12:21:50
【问题描述】:

几天以来,我们在构建 TFS 时遇到了问题。我们在一些单元测试中使用 Microsoft Shims/Fakes,到目前为止我们没有遇到任何问题。 但最近 UnitTest 步骤失败并出现以下错误: 每隔一段时间就会发生以下情况:

2016-07-01T06:40:25.3532321Z ##[error]Error: System.IO.IOException: The process cannot access the file 'D:\Builds\Agent\87a4a39e\...\bin\Debug\mscorlib.4.0.0.0.Fakes.FakedTypesCache' because it is being used by another process.

2016-07-01T06:40:25.3532321Z ##[error]   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

2016-07-01T06:40:25.3532321Z ##[error]   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)

2016-07-01T06:40:25.3532321Z ##[error]   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)

2016-07-01T06:40:25.3532321Z ##[error]   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)

2016-07-01T06:40:25.3532321Z ##[error]   at System.IO.StreamReader..ctor(String path)

2016-07-01T06:40:25.3532321Z ##[error]   at Microsoft.VisualStudio.TraceCollector.FakesAssemblyReflector.LoadShimTypesFromCache(String fakedTypesCacheFilePath)

2016-07-01T06:40:25.3532321Z ##[error]   at Microsoft.VisualStudio.TraceCollector.FakesAssemblyReflector.ReflectShimTypes(String fakesAssemblyFullPath)

2016-07-01T06:40:25.3532321Z ##[error]   at Microsoft.VisualStudio.TraceCollector.UnitTestIsolationDataCollector.PopulateCollectionPlan(_CollectionPlan plan, XmlElement settings)

2016-07-01T06:40:25.3532321Z ##[error]   at Microsoft.VisualStudio.TraceCollector.UnitTestIsolationDataCollector.OnSecondCollectorToInitialize(_CollectionPlan plan, XmlElement configurationElement)

2016-07-01T06:40:25.3532321Z ##[error]   at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.OnInitialize(XmlElement configurationElement)

2016-07-01T06:40:25.3532321Z ##[error]   at Microsoft.VisualStudio.TraceCollector.BaseDataCollector.InternalConstruct(XmlElement configurationElement, IDataCollectionEvents events, IDataCollectionSink dataSink, IDataCollectionLogger logger, IDataCollectionAgentContext agentContext)

2016-07-01T06:40:25.3532321Z ##[error]   at Microsoft.VisualStudio.TraceCollector.BaseDataCollector.Initialize(XmlElement configurationElement, DataCollectionEvents events, DataCollectionSink dataSink, DataCollectionLogger logger, DataCollectionEnvironmentContext environmentContext)

2016-07-01T06:40:25.3532321Z ##[error]   at WEX.TestExecution.DataCollectorTestMode.Initialize(ITestModeSettings settings, ICallbackRegistrar callbackRegistrar)

2016-07-01T06:40:25.3532321Z ##[error]

我不确定它是否与我们的代码覆盖率有关(因为堆栈跟踪提到了这个数据收集器)。我们使用 runsettings 文件从代码覆盖范围内/排除某些内容。

在构建服务器上,我们安装了 Visual Studio 2015 Update 3(但问题也出现在 Update 2 中),并且 TFS 是 2015 RTM 版本。

明显被锁定的文件并不总是相同的,但它总是“FakeTypeCaches”之一。

任何帮助将不胜感激

谢谢

编辑

似乎问题是由并行运行单元测试引起的(我认为该选项自 VS 2015 Update 1 起可用)。不并行运行它们似乎已经解决了问题,但遗憾的是现在运行我们的测试需要更长的时间才能运行。特别是对于我们的 CI 构建来说,这并不理想,因为我们希望尽快获得反馈。 如果我们只能按顺序运行使用 Faked/Stubbed 类的测试,那将是理想的,但据我所知,我不知道如何实现这一目标。

我们现在解决此问题的解决方案是使用 TestCategory 标记所有使用 Fakes/Shims 的测试:[TestCategory("Sequential")]

在构建服务器上,我们定义了两个单元测试步骤,第一个过滤除“Sequential”之外的所有类别并并行运行,第二个然后不并行运行“Sequential”。

【问题讨论】:

  • 您的构建服务器上是否有多个构建代理?如果您尝试使用另一个构建代理来构建它会产生什么结果?
  • 您好,我们在构建服务器上只有一个构建代理。

标签: c# visual-studio tfs


【解决方案1】:

根据错误消息,似乎有其他进程持有该文件。 尝试使用this tool 来确定哪个文件正在被哪个进程锁定。然后在构建过程中停止该过程。

【讨论】:

    【解决方案2】:

    这是Update for Microsoft Visual Studio 2015 Update 2 (KB3151378) 中修复的已知问题。

    您应该只获取 Visual Studio 的最新更新,在此答案时是:Visual Studio 2015 Update 3

    【讨论】:

    • 嗨,当问题第一次出现时,我们实际上使用的是 Visual Studio Update 2。现在我们已经升级到 Update 3,我会再试一次。
    • 我们有这个问题,我们的构建服务器有 Visual Studio 2015 Update 3。提供的链接中的相关已知问题是什么?我看不到任何相关的内容。
    • 我们仍然有更新 3 的问题。
    【解决方案3】:

    我们在 TFS2015 Update3 On-Promise 上,我们在并行运行单元测试时遇到了同样的问题。 我们的短期解决方案是禁用 Repository clean 选项,并且只使用 MSBuild clean,所以那些假缓存文件不会被清理。似乎只有在多个测试同时尝试创建假缓存文件时才会发生错误。

    但是,禁用 Repository clean 选项后,我们还遇到了一些其他随机烦人的问题。 :(。

    如果您找到了避免此问题的更好方法,请告诉我。 谢谢, 天使

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-08
      • 1970-01-01
      • 2017-09-17
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      相关资源
      最近更新 更多