2013-07-29 69 views
1

我試圖用specflow/CodedUI/VSTS 2012Specflow情況下拋出異常與Visual Studio 2012

做UI自動化當我嘗試運行的情況下,我收到以下錯誤: 無法加載文件或程序集'Microsoft.VisualStudio.TestTools.UITest.Playback,版本= 11.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依賴項之一。該系統找不到指定的文件。

誰能告訴我如何解決這個錯誤?

+0

不這發生在您的開發機器上,還是僅在構建服務器上? – AlSki

+0

它發生在開發機器上... – Sourabh

回答

1

最後我找到了解決這個問題的方法。我不知道爲什麼,但你必須編寫你自己的程序集解析器。我發現這裏的解決方案:

http://blog.csdn.net/marryshi/article/details/8100194

然而,我不得不更新爲VS2012的註冊表路徑:

static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) 
{ 
    AssemblyName assemblyName = new AssemblyName(args.Name); 
    if (assemblyName.Name.StartsWith("Microsoft.VisualStudio.TestTools.UITest", StringComparison.Ordinal)) 
    { 
     string path = string.Empty; 
     using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\VisualStudio\11.0")) 
     { 
      if (key != null) 
      { 
       path = key.GetValue("InstallDir") as string; 
      } 
     } 

     if (!string.IsNullOrWhiteSpace(path)) 
     { 
      string assemblyPath = Path.Combine(path, "PublicAssemblies", 
       string.Format(CultureInfo.InvariantCulture, "{0}.dll", assemblyName.Name)); 

      if (!File.Exists(assemblyPath)) 
      { 
       assemblyPath = Path.Combine(path, "PrivateAssemblies", 
        string.Format(CultureInfo.InvariantCulture, "{0}.dll", assemblyName.Name)); 

       if (!File.Exists(assemblyPath)) 
       { 
        string commonFiles = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86); 
        if (string.IsNullOrWhiteSpace(commonFiles)) 
        { 
         commonFiles = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles); 
        } 

        assemblyPath = Path.Combine(commonFiles, "Microsoft Shared", "VSTT", "10.0", 
         string.Format(CultureInfo.InvariantCulture, "{0}.dll", assemblyName.Name)); 
       } 
      } 

      if (File.Exists(assemblyPath)) 
      { 
       return Assembly.LoadFrom(assemblyPath); 
      } 
     } 
    } 

    return null; 
} 

我運行功能之前,註冊表解析:

[BeforeFeature] 
public static void Initialize() 
{ 
    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); 
} 
相關問題