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;
}
}
}