/// <summary> /// Creates a new CreateOpenRiaClientFilesTask 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 CreateOpenRiaClientFilesTask CreateOpenRiaClientFilesTaskInstance_CopyClientProjectToOutput(string serverProjectPath, string clientProjectPath, bool includeClientOutputAssembly) { CreateOpenRiaClientFilesTask task = new CreateOpenRiaClientFilesTask(); 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.GetClientRuntimeDirectory(); // 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> /// 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) { string projectPath = string.Empty; // path to current project string outputPath = string.Empty; // 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 string projectDir = Path.GetDirectoryName(projectPath); // Folder of project we want to build string testProjectDir = Path.GetFullPath(Path.Combine(projectDir, @"..\..\OpenRiaServices.DomainServices.Client.Web\Framework")); string projectOutputDir = Path.Combine(testProjectDir, outputPath); string testProjectFile = Path.Combine(testProjectDir, @"OpenRiaServices.DomainServices.Client.Web.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) List <string> assemblies = MsBuildHelper.GetReferenceAssemblies(testProjectFile); string outputAssembly = MsBuildHelper.GetOutputAssembly(testProjectFile); if (!string.IsNullOrEmpty(outputAssembly)) { assemblies.Add(outputAssembly); } return(assemblies); }
/// <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)); }
internal static string GetFailedToOpenProjectMessage(string badProjectPath) { // Simulate the exception so we get the exact text try { MsBuildHelper.LoadProject(badProjectPath); } catch (InvalidProjectFileException ipfe) { return(string.Format(CultureInfo.CurrentCulture, Resource.Failed_To_Open_Project, badProjectPath, ipfe.Message)); } Assert.Fail("load should have failed"); return(null); }
/// <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> /// Creates a new <see cref="ValidateDomainServicesTask"/> instance /// </summary> /// <param name="relativeTestDir">The relative output directory of the test</param> /// <returns>A new <see cref="ValidateDomainServicesTask"/> instance</returns> public static ValidateDomainServicesTask CreateValidateDomainServicesTask(string relativeTestDir) { string deploymentDir = Path.GetDirectoryName(typeof(CodeGenHelper).Assembly.Location); string projectPath = null; string outputPath = null; TestHelper.GetProjectPaths(relativeTestDir, out projectPath, out outputPath); Assert.IsTrue(File.Exists(projectPath), "Could not locate " + projectPath + " necessary for test."); string serverProjectPath = CodeGenHelper.ServerClassLibProjectPath(projectPath); ValidateDomainServicesTask task = new ValidateDomainServicesTask(); MockBuildEngine mockBuildEngine = new MockBuildEngine(); task.BuildEngine = mockBuildEngine; task.ProjectPath = serverProjectPath; task.Assembly = new TaskItem(CodeGenHelper.ServerClassLibOutputAssembly(task.ProjectPath)); task.ReferenceAssemblies = MsBuildHelper.AsTaskItems(CodeGenHelper.ServerClassLibReferences(task.ProjectPath)).ToArray(); return(task); }
/// <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)); }