1

我正在尝试使用 specflow/CodedUI/VSTS 2012 进行 UI 自动化。

当我尝试运行该方案时,我收到以下错误:无法加载文件或程序集“Microsoft.VisualStudio.TestTools.UITest.Playback, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其之一依赖关系。该系统找不到指定的文件。

谁能告诉我如何解决这个错误?

4

1 回答 1

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);
}
于 2014-03-25T18:06:01.767 回答