【问题标题】:Specflow scenarios throws exception with Visual Studio 2012Specflow 场景在 Visual Studio 2012 中引发异常
【发布时间】:2013-07-28 23:33:24
【问题描述】:

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

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

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

【问题讨论】:

  • 这是在您的开发机器上发生,还是仅在构建服务器上发生?
  • 这发生在开发机器上...

标签: coded-ui-tests specflow


【解决方案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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多