Dot-Net

Microsoft.Build.Utilities.FileTracker 引發異常錯誤。發生在不同的項目中

  • July 29, 2013

最近在 Win7 64 位中使用 Visual Studio 2010 Ultimate,C#,編譯任何項目時都會出現以下錯誤。解決方法是添加<TrackFileAccess>false</TrackFileAccess>到項目文件中。如果我沒記錯的話,這會禁用增量建構,所以我想遠離這種解決方法。

任何人都知道永久可靠修復是什麼?我確實重新安裝了 .NET Framework 4 和 VS 2010。我沒有 4.0 框架文件夾的測試版或早期版本。

Error   1   The "GenerateResource" task failed unexpectedly.
System.TypeInitializationException: The type initializer for 'Microsoft.Build.Utilities.FileTracker' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
  at Microsoft.Build.Utilities.FileTracker..cctor()
  --- End of inner exception stack trace ---
  at Microsoft.Build.Utilities.FileTracker.ForceOutOfProcTracking(ExecutableType toolType, String dllName, String cancelEventName)
  at Microsoft.Build.Tasks.GenerateResource.Execute()
  at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
  at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext 

我通過反映 Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Build.Utilities.v4.0.dll 找到了適合我環境的解決方案

我的 TEMP/TMP 環境變數指向 ram 驅動器根文件夾 (T:),沒有任何進一步的目錄嵌套!行s_tempPath = Path.GetDirectoryName(Path.GetTempPath()); 在 Microsoft.Build.Utilities.FileTracker 的靜態 ctor 中導致 null,這導致了您提到的異常。

現在我的 TEMP/TMP 環境變數指向 T:\TEMP,一切正常。

老問題,但我希望它會幫助Google搜尋它的人。它不完全是由微軟跟踪的錯誤引起的原始問題中的 Nullref,但我想分享它。

我在建構 C++ 項目時遇到了嚴重問題,我發現這是由 Temp 環境變數(可能在路徑名中包含空格)引起的。

Unerwarteter Fehler bei der CL-Aufgabe.
System.TypeInitializationException: Der Typeninitialisierer für "Microsoft.Build.Utilities.FileTracker" hat eine Ausnahme verursacht. ---> System.IO.FileNotFoundException: Das System kann die angegebene Datei nicht finden. (Ausnahme von HRESULT: 0x80070002)
  bei System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
  bei System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
  bei Microsoft.Build.Shared.NativeMethodsShared.ThrowExceptionForErrorCode(Int32 errorCode)
  bei Microsoft.Build.Shared.NativeMethodsShared.GetLongFilePath(String path)
  bei Microsoft.Build.Utilities.FileTracker..cctor()
  --- Ende der internen Ausnahmestapelüberwachung ---
  bei Microsoft.Build.CPPTasks.CL.ComputeOutOfDateSources()
  bei Microsoft.Build.CPPTasks.TrackedVCToolTask.SkipTaskExecution()
  bei Microsoft.Build.Utilities.ToolTask.Execute()
  bei Microsoft.Build.CPPTasks.TrackedVCToolTask.Execute()
  bei Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
  bei Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext()

將 TEMP 和 TMP 更改為:

%USERPROFILE%\Appdata\Local\Temp

解決了。

引用自:https://stackoverflow.com/questions/3221565