/// <summary> /// Creates a new CreateClientFilesTask instance to use to generate code /// </summary> /// <param name="relativeTestDir"></param> /// <param name="includeClientOutputAssembly">if <c>true</c> include clients own output assembly in analysis</param> /// <returns>A new task instance that can be invoked to do code gen</returns> public static CreateClientFilesTask CreateClientFilesTaskInstance_CopyClientProjectToOutput(string serverProjectPath, string clientProjectPath, bool includeClientOutputAssembly) { CreateClientFilesTask task = new CreateClientFilesTask(); MockBuildEngine mockBuildEngine = new MockBuildEngine(); task.BuildEngine = mockBuildEngine; task.Language = "C#"; task.ServerProjectPath = serverProjectPath; task.ServerAssemblies = new TaskItem[] { new TaskItem(CodeGenHelper.ServerClassLibOutputAssembly(task.ServerProjectPath)) }; task.ServerReferenceAssemblies = MsBuildHelper.AsTaskItems(CodeGenHelper.ServerClassLibReferences(task.ServerProjectPath)).ToArray(); task.ClientFrameworkPath = CodeGenHelper.GetRuntimeDirectory(); // Generate the code to our deployment directory string tempFolder = CodeGenHelper.GenerateTempFolder(); task.OutputPath = Path.Combine(tempFolder, "FileWrites"); task.GeneratedCodePath = Path.Combine(tempFolder, "Generated_Code"); string clientProjectFileName = Path.GetFileName(clientProjectPath); string clientProjectDestPath = Path.Combine(tempFolder, clientProjectFileName); File.Copy(clientProjectPath, clientProjectDestPath); task.ClientProjectPath = clientProjectDestPath; task.ClientReferenceAssemblies = MsBuildHelper.AsTaskItems(CodeGenHelper.ClientClassLibReferences(clientProjectPath, includeClientOutputAssembly)).ToArray(); task.ClientSourceFiles = MsBuildHelper.AsTaskItems(CodeGenHelper.ClientClassLibSourceFiles(clientProjectPath)).ToArray(); return(task); }
/// <summary> /// Returns the name of the assembly built by the server project /// </summary> /// <param name="serverProjectPath"></param> /// <returns></returns> public static string ServerClassLibOutputAssembly(string serverProjectPath) { // We need to map any server side assembly references back to our deployment directory // if we have the same assembly there, otherwise the assembly load from calls end up // with multiple assemblies with the same types string deploymentDir = Path.GetDirectoryName(typeof(CodeGenHelper).Assembly.Location); string assembly = MsBuildHelper.GetOutputAssembly(serverProjectPath); return(MapAssemblyReferenceToDeployment(deploymentDir, assembly)); }
/// <summary> /// Extract the list of assemblies both generated and referenced by client. /// Not coincidently, this list is what a client project needs to reference. /// </summary> /// <returns></returns> public static List <string> GetClientAssemblies(string relativeTestDir) { var assemblies = new List <string>(); string projectPath, outputPath; // output path for current project, used to infer output path of test project TestHelper.GetProjectPaths(relativeTestDir, out projectPath, out outputPath); // Our current project's folder var projectDir = Path.GetDirectoryName(projectPath); // Folder of project we want to build var testProjectDir = Path.GetFullPath(Path.Combine(projectDir, @"..\..\Luma.SimpleEntity.Client")); var testProjectFile = Path.Combine(testProjectDir, @"Luma.SimpleEntity.Client.csproj"); Assert.IsTrue(File.Exists(testProjectFile), "This test could not find its required project at " + testProjectFile); // Retrieve all the assembly references from the test project (follows project-to-project references too) MsBuildHelper.GetReferenceAssemblies(testProjectFile, assemblies); var outputAssembly = MsBuildHelper.GetOutputAssembly(testProjectFile); if (!string.IsNullOrEmpty(outputAssembly)) { assemblies.Add(outputAssembly); } var frameworkDirectory = CodeGenHelper.GetRuntimeDirectory(); var frameworkAssemblies = Directory.EnumerateFiles(frameworkDirectory, "*.dll"); foreach (var frameworkAssembly in frameworkAssemblies) { if (!assemblies.Contains(frameworkAssembly)) { assemblies.Add(frameworkAssembly); } } return(assemblies); }
/// <summary> /// Returns the collection of assembly references from the client project /// </summary> /// <param name="clientProjectPath"></param> /// <returns></returns> public static List <string> ClientClassLibReferences(string clientProjectPath, bool includeClientOutputAssembly) { List <string> references = MsBuildHelper.GetReferenceAssemblies(clientProjectPath); // Note: we conditionally add the output assembly to enable this unit test to // define some shared types if (includeClientOutputAssembly) { references.Add(MsBuildHelper.GetOutputAssembly(clientProjectPath)); } // Remove mscorlib -- it causes problems using ReflectionOnlyLoad ("parent does not exist") for (int i = 0; i < references.Count; ++i) { if (Path.GetFileName(references[i]).Equals("mscorlib.dll", StringComparison.OrdinalIgnoreCase)) { references.RemoveAt(i); break; } } return(references); }
/// <summary> /// Returns the collection of source files from the client /// </summary> /// <param name="clientProjectPath"></param> /// <returns></returns> public static List <string> ClientClassLibSourceFiles(string clientProjectPath) { return(MsBuildHelper.GetSourceFiles(clientProjectPath)); }
/// <summary> /// Returns the collection of source files from the server /// </summary> /// <param name="serverProjectPath"></param> /// <returns></returns> public static List <string> ServerClassLibSourceFiles(string serverProjectPath) { return(MsBuildHelper.GetSourceFiles(serverProjectPath)); }