您的位置:首页 > Web前端

how to fix the assembly problem when project A call project B as reference

2012-10-22 19:54 591 查看
1. Project B is coded with CodedUI Test

2. Project A is a Console Application, which has a reference from project B.

When run project A, there is a exception from project B on "playback.playbacksettings":

"

": Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Playback, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one
of its dependencies. The system cannot find the file specified.":"Microsoft.VisualStudio.TestTools.UITest.Playback, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Resolution:

1. Add reference to Microsoft.VisualStudio.TestTools.UITesting.dll, Microsoft.VisualStudio.TestTools.UITest.Extension.dll and Microsoft.VisualStudio.TestTools.UITest.Common.dll with CopyLocal as false.

2. Write an assembly resolver. Follow the code below

using System;

using System.Reflection;

using System.Globalization;

using System.IO;

using Microsoft.Win32;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

// Your code here.

}

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\10.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;

}

}

}

info from: http://blogs.kungfucoder.com/blog/post/2011/10/11/Coded-UI-Testing-Could-not-load-Visual-Studio-Test-Assembly.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐