/// <summary> /// Invokes the T4 generator to emit a platform-specific project file. /// </summary> /// <param name="projectFileConfiguration"></param> /// <param name="session"></param> /// <param name="serviceFilesRoot"></param> /// <param name="projectFilename"></param> private void GenerateProjectFile(ProjectFileConfiguration projectFileConfiguration, ProjectConfigurationData projectConfiguration, IDictionary <string, object> session, string serviceFilesRoot, string projectFilename) { var projectName = Path.GetFileNameWithoutExtension(projectFilename); string generatedContent = null; try { var projectTemplateType = Type.GetType( "ServiceClientGenerator.Generators.ProjectFiles." + projectFileConfiguration.Template); dynamic generator = Activator.CreateInstance(projectTemplateType); generator.Session = session; generatedContent = generator.TransformText(); } catch (Exception) { throw new ArgumentException("Project template name " + projectFileConfiguration.Template + " is not recognized"); } GeneratorDriver.WriteFile(serviceFilesRoot, string.Empty, projectFilename, generatedContent); projectConfiguration.ConfigurationPlatforms = projectFileConfiguration.Configurations; }
public void ExecuteCore(string coreFilesRoot, IEnumerable<ProjectFileConfiguration> projectFileConfigurations) { CreatedProjectFiles = new Dictionary<string, ProjectConfigurationData>(); foreach (var projectFileConfiguration in projectFileConfigurations) { var projectType = projectFileConfiguration.Name; var assemblyName = "AWSSDK.Core"; var projectFilename = string.Concat(assemblyName, ".", projectType, ".csproj"); bool newProject = false; string projectGuid; if (File.Exists(Path.Combine(coreFilesRoot, projectFilename))) { Console.WriteLine("...updating existing project file {0}", projectFilename); var projectPath = Path.Combine(coreFilesRoot, projectFilename); projectGuid = Utils.GetProjectGuid(projectPath); } else { newProject = true; projectGuid = Utils.NewProjectGuid; Console.WriteLine("...creating project file {0}", projectFilename); } var templateSession = new Dictionary<string, object>(); templateSession["Name"] = projectFileConfiguration.Name; templateSession["ProjectGuid"] = projectGuid; templateSession["RootNamespace"] = "Amazon"; templateSession["AssemblyName"] = assemblyName; templateSession["SourceDirectories"] = GetCoreProjectSourceFolders(projectFileConfiguration, coreFilesRoot); templateSession["IndividualFileIncludes"] = new List<string> { "endpoints.json", }; templateSession["KeyFilePath"] = @"..\..\awssdk.dll.snk"; templateSession["SupressWarnings"] = "419,1570,1591"; templateSession["NugetPackagesLocation"] = @"..\..\packages\"; templateSession["TargetFrameworkVersion"] = projectFileConfiguration.TargetFrameworkVersion; templateSession["DefineConstants"] = projectFileConfiguration.CompilationConstants; templateSession["BinSubfolder"] = projectFileConfiguration.BinSubFolder; var projectConfigurationData = new ProjectConfigurationData { ProjectGuid = projectGuid }; var projectName = Path.GetFileNameWithoutExtension(projectFilename); if (newProject) CreatedProjectFiles[projectName] = projectConfigurationData; var projectReferences = new List<ProjectReference>(); templateSession["ProjectReferences"] = projectReferences.OrderBy(x => x.Name).ToList(); templateSession["UnityPath"] = Options.UnityPath; GenerateProjectFile(projectFileConfiguration, projectConfigurationData, templateSession, coreFilesRoot, projectFilename); } }
public void ExecuteCore(string coreFilesRoot, IEnumerable <ProjectFileConfiguration> projectFileConfigurations) { CreatedProjectFiles = new Dictionary <string, ProjectConfigurationData>(); foreach (var projectFileConfiguration in projectFileConfigurations) { var projectType = projectFileConfiguration.Name; var assemblyName = "AWSSDK.Core"; var projectFilename = string.Concat(assemblyName, ".", projectType, ".csproj"); bool newProject = false; if (projectFileConfiguration.Template.Equals("VS2017ProjectFile", StringComparison.InvariantCultureIgnoreCase)) { // for vs2017 projects, skip csproject generation } else { string projectGuid; if (File.Exists(Path.Combine(coreFilesRoot, projectFilename))) { Console.WriteLine("...updating existing project file {0}", projectFilename); var projectPath = Path.Combine(coreFilesRoot, projectFilename); projectGuid = Utils.GetProjectGuid(projectPath); } else { newProject = true; projectGuid = Utils.NewProjectGuid; Console.WriteLine("...creating project file {0}", projectFilename); } var templateSession = new Dictionary <string, object>(); templateSession["Name"] = projectFileConfiguration.Name; templateSession["ProjectGuid"] = projectGuid; templateSession["RootNamespace"] = "Amazon"; templateSession["AssemblyName"] = assemblyName; templateSession["SourceDirectories"] = GetCoreProjectSourceFolders(projectFileConfiguration, coreFilesRoot); templateSession["IndividualFileIncludes"] = new List <string> { "endpoints.json", }; templateSession["KeyFilePath"] = @"..\..\awssdk.dll.snk"; templateSession["SupressWarnings"] = "419,1570,1591"; templateSession["NugetPackagesLocation"] = @"..\..\packages\"; templateSession["TargetFrameworkVersion"] = projectFileConfiguration.TargetFrameworkVersion; templateSession["DefineConstants"] = projectFileConfiguration.CompilationConstants; templateSession["BinSubfolder"] = projectFileConfiguration.BinSubFolder; var projectConfigurationData = new ProjectConfigurationData { ProjectGuid = projectGuid }; var projectName = Path.GetFileNameWithoutExtension(projectFilename); if (newProject) { CreatedProjectFiles[projectName] = projectConfigurationData; } var projectReferences = new List <ProjectReference>(); templateSession["ProjectReferences"] = projectReferences.OrderBy(x => x.Name).ToList(); templateSession["UnityPath"] = Options.UnityPath; GenerateProjectFile(projectFileConfiguration, projectConfigurationData, templateSession, coreFilesRoot, projectFilename); } } }
/// <summary> /// Creates the platform-specific project files for the given service configuration /// </summary> /// <param name="serviceFilesRoot">The folder under which all of the source files for the service will exist</param> /// <param name="serviceConfiguration"></param> /// <param name="projectFileConfigurations"></param> public void Execute(string serviceFilesRoot, ServiceConfiguration serviceConfiguration, IEnumerable <ProjectFileConfiguration> projectFileConfigurations) { CreatedProjectFiles = new Dictionary <string, ProjectConfigurationData>(); var assemblyName = "AWSSDK." + serviceConfiguration.Namespace.Split('.')[1]; foreach (var projectFileConfiguration in projectFileConfigurations) { var projectType = projectFileConfiguration.Name; if (projectType.Equals("Unity", StringComparison.InvariantCultureIgnoreCase) && !serviceConfiguration.SupportedInUnity) { continue; } if (projectType.Equals("CoreCLR", StringComparison.InvariantCultureIgnoreCase) && !serviceConfiguration.CoreCLRSupport) { continue; } if (projectFileConfiguration.Template.Equals("VS2017ProjectFile", StringComparison.InvariantCultureIgnoreCase)) { var projectReferenceList = new List <ProjectReference>(); foreach (var dependency in serviceConfiguration.ServiceDependencies.Keys) { if (string.Equals(dependency, "Core", StringComparison.InvariantCultureIgnoreCase)) { continue; } projectReferenceList.Add(new ProjectReference { IncludePath = string.Format(@"..\..\Services\{0}\AWSSDK.{1}.{2}.csproj", dependency, dependency, projectType) }); } projectReferenceList.Add(new ProjectReference { IncludePath = string.Format(@"..\..\Core\AWSSDK.Core.{0}.csproj", projectType) }); projectFileConfiguration.ProjectReferences = projectReferenceList; GenerateVS2017ProjectFile(serviceFilesRoot, serviceConfiguration, projectFileConfiguration); continue; } if (projectFileConfiguration.IsSubProfile && !(serviceConfiguration.PclVariants != null && serviceConfiguration.PclVariants.Any(p => p.Equals(projectFileConfiguration.Name)))) { // Skip sub profiles for service projects. continue; } var projectFilename = string.Concat(assemblyName, ".", projectType, ".csproj"); bool newProject = false; string projectGuid; if (File.Exists(Path.Combine(serviceFilesRoot, projectFilename))) { Console.WriteLine("...updating existing project file {0}", projectFilename); var projectPath = Path.Combine(serviceFilesRoot, projectFilename); projectGuid = Utils.GetProjectGuid(projectPath); } else { newProject = true; projectGuid = Utils.NewProjectGuid; Console.WriteLine("...creating project file {0}", projectFilename); } var templateSession = new Dictionary <string, object>(); templateSession["Name"] = projectFileConfiguration.Name; templateSession["ProjectGuid"] = projectGuid; templateSession["RootNamespace"] = serviceConfiguration.Namespace; templateSession["AssemblyName"] = assemblyName; templateSession["SourceDirectories"] = GetProjectSourceFolders(projectFileConfiguration, serviceFilesRoot); templateSession["NugetPackagesLocation"] = @"..\..\..\packages\"; templateSession["TargetFrameworkVersion"] = projectFileConfiguration.TargetFrameworkVersion; templateSession["DefineConstants"] = projectFileConfiguration.CompilationConstants; templateSession["BinSubfolder"] = projectFileConfiguration.BinSubFolder; var projectConfigurationData = new ProjectConfigurationData { ProjectGuid = projectGuid }; var projectName = Path.GetFileNameWithoutExtension(projectFilename); if (newProject) { CreatedProjectFiles[projectName] = projectConfigurationData; } var projectReferences = new List <ProjectReference>(); if (serviceConfiguration.ServiceDependencies != null) { foreach (var dependency in serviceConfiguration.ServiceDependencies) { var pt = projectType; if (!(pt.StartsWith(@"Net") || pt.StartsWith(@"Unity")) && serviceConfiguration.UsePclProjectDependencies) { pt = @"PCL"; } var dependencyProjectName = "AWSSDK." + dependency.Key + "." + pt; string dependencyProject; if (string.Equals(dependency.Key, "Core", StringComparison.InvariantCultureIgnoreCase)) { dependencyProject = string.Concat(@"..\..\", dependency.Key, "\\", dependencyProjectName, ".csproj"); } else { dependencyProject = string.Concat(@"..\", dependency.Key, "\\", dependencyProjectName, ".csproj"); } projectReferences.Add(new ProjectReference { IncludePath = dependencyProject, ProjectGuid = Utils.GetProjectGuid(Path.Combine(serviceFilesRoot, dependencyProject)), Name = dependencyProjectName }); } } templateSession["ProjectReferences"] = projectReferences.OrderBy(x => x.Name).ToList(); templateSession["UnityPath"] = Options.UnityPath; if (serviceConfiguration.ModelName.Equals("s3", StringComparison.OrdinalIgnoreCase) && projectType == "Net45") { templateSession["SystemReferences"] = new List <string> { "System.Net.Http" }; } if (serviceConfiguration.ReferenceDependencies != null && serviceConfiguration.ReferenceDependencies.ContainsKey(projectFileConfiguration.Name)) { templateSession["ReferenceDependencies"] = serviceConfiguration.ReferenceDependencies[projectFileConfiguration.Name]; templateSession["NuGetTargetFramework"] = projectFileConfiguration.NuGetTargetPlatform; } GenerateProjectFile(projectFileConfiguration, projectConfigurationData, templateSession, serviceFilesRoot, projectFilename); } }
public void ExecuteCore(string coreFilesRoot, IEnumerable <ProjectFileConfiguration> projectFileConfigurations) { CreatedProjectFiles = new Dictionary <string, ProjectConfigurationData>(); foreach (var projectFileConfiguration in projectFileConfigurations) { var projectType = projectFileConfiguration.Name; var assemblyName = "AWSSDK.Core"; var projectFilename = string.Concat(assemblyName, ".", projectType, ".csproj"); bool newProject = false; if (projectFileConfiguration.Template.Equals("VS2017ProjectFile", StringComparison.InvariantCultureIgnoreCase)) { // for vs2017 projects, skip csproject generation } else { string projectGuid; if (File.Exists(Path.Combine(coreFilesRoot, projectFilename))) { Console.WriteLine("...updating existing project file {0}", projectFilename); var projectPath = Path.Combine(coreFilesRoot, projectFilename); projectGuid = Utils.GetProjectGuid(projectPath); } else { newProject = true; projectGuid = Utils.NewProjectGuid; Console.WriteLine("...creating project file {0}", projectFilename); } var projectProperties = new Project(); projectProperties.Name = projectFileConfiguration.Name; projectProperties.ProjectGuid = projectGuid; projectProperties.RootNamespace = "Amazon"; projectProperties.AssemblyName = assemblyName; projectProperties.SourceDirectories = GetCoreProjectSourceFolders(projectFileConfiguration, coreFilesRoot); projectProperties.IndividualFileIncludes = new List <string> { "endpoints.json", }; projectProperties.KeyFilePath = @"..\..\awssdk.dll.snk"; projectProperties.SupressWarnings = "419,1570,1591"; projectProperties.NugetPackagesLocation = @"..\..\packages\"; projectProperties.FxcopAnalyzerRuleSetFilePath = @"..\..\AWSDotNetSDK.ruleset"; projectProperties.FxcopAnalyzerRuleSetFilePathForBuild = @"..\..\AWSDotNetSDKForBuild.ruleset"; projectProperties.TargetFrameworks = projectFileConfiguration.TargetFrameworkVersions; projectProperties.DefineConstants = projectFileConfiguration.CompilationConstants; projectProperties.BinSubfolder = projectFileConfiguration.BinSubFolder; projectProperties.PackageReferences = projectFileConfiguration.PackageReferences; projectProperties.CustomRoslynAnalyzersDllDirectory = @"..\..\..\buildtools\CustomRoslynAnalyzers.dll"; var projectConfigurationData = new ProjectConfigurationData { ProjectGuid = projectGuid }; var projectName = Path.GetFileNameWithoutExtension(projectFilename); if (newProject) { CreatedProjectFiles[projectName] = projectConfigurationData; } var projectReferences = new List <ProjectReference>(); projectProperties.ProjectReferences = projectReferences.OrderBy(x => x.Name).ToList(); GenerateProjectFile(projectFileConfiguration, projectConfigurationData, projectProperties, coreFilesRoot, projectFilename); } } }
/// <summary> /// Creates the platform-specific project files for the given service configuration /// </summary> /// <param name="serviceFilesRoot">The folder under which all of the source files for the service will exist</param> /// <param name="serviceConfiguration"></param> /// <param name="projectFileConfigurations"></param> public void Execute(string serviceFilesRoot, ServiceConfiguration serviceConfiguration, IEnumerable <ProjectFileConfiguration> projectFileConfigurations) { CreatedProjectFiles = new Dictionary <string, ProjectConfigurationData>(); var assemblyName = "AWSSDK." + serviceConfiguration.Namespace.Split('.')[1]; foreach (var projectFileConfiguration in projectFileConfigurations) { var projectType = projectFileConfiguration.Name; if (projectType.Equals("NetStandard", StringComparison.InvariantCultureIgnoreCase) && !serviceConfiguration.NetStandardSupport) { continue; } if (projectFileConfiguration.Template.Equals("VS2017ProjectFile", StringComparison.InvariantCultureIgnoreCase)) { var projectReferenceList = new List <ProjectReference>(); foreach (var dependency in serviceConfiguration.ServiceDependencies.Keys) { if (string.Equals(dependency, "Core", StringComparison.InvariantCultureIgnoreCase)) { continue; } projectReferenceList.Add(new ProjectReference { IncludePath = string.Format(@"..\..\Services\{0}\AWSSDK.{1}.{2}.csproj", dependency, dependency, projectType) }); } var corePath = @"..\..\Core\AWSSDK.Core.{0}.csproj"; if (serviceConfiguration.IsTestService) { corePath = @"..\..\..\src\Core\AWSSDK.Core.{0}.csproj"; } projectReferenceList.Add(new ProjectReference { IncludePath = string.Format(corePath, projectType) }); projectFileConfiguration.ProjectReferences = projectReferenceList; GenerateVS2017ProjectFile(serviceFilesRoot, serviceConfiguration, projectFileConfiguration); continue; } var projectFilename = string.Concat(assemblyName, ".", projectType, ".csproj"); bool newProject = false; string projectGuid; if (File.Exists(Path.Combine(serviceFilesRoot, projectFilename))) { Console.WriteLine("...updating existing project file {0}", projectFilename); var projectPath = Path.Combine(serviceFilesRoot, projectFilename); projectGuid = Utils.GetProjectGuid(projectPath); } else { newProject = true; projectGuid = Utils.NewProjectGuid; Console.WriteLine("...creating project file {0}", projectFilename); } var projectProperties = new Project(); projectProperties.Name = projectFileConfiguration.Name; projectProperties.ProjectGuid = projectGuid; projectProperties.RootNamespace = serviceConfiguration.Namespace; projectProperties.AssemblyName = assemblyName; projectProperties.SourceDirectories = GetProjectSourceFolders(projectFileConfiguration, serviceFilesRoot); projectProperties.NugetPackagesLocation = @"..\..\..\packages\"; projectProperties.FxcopAnalyzerRuleSetFilePath = @"..\..\..\AWSDotNetSDK.ruleset"; projectProperties.FxcopAnalyzerRuleSetFilePathForBuild = @"..\..\..\AWSDotNetSDKForBuild.ruleset"; projectProperties.TargetFrameworks = projectFileConfiguration.TargetFrameworkVersions; projectProperties.DefineConstants = projectFileConfiguration.CompilationConstants; projectProperties.BinSubfolder = projectFileConfiguration.BinSubFolder; projectProperties.PackageReferences = projectFileConfiguration.PackageReferences; projectProperties.CustomRoslynAnalyzersDllDirectory = @"..\..\..\..\buildtools\CustomRoslynAnalyzers.dll"; var projectConfigurationData = new ProjectConfigurationData { ProjectGuid = projectGuid }; var projectName = Path.GetFileNameWithoutExtension(projectFilename); if (newProject) { CreatedProjectFiles[projectName] = projectConfigurationData; } var projectReferences = new List <ProjectReference>(); if (serviceConfiguration.ServiceDependencies != null) { foreach (var dependency in serviceConfiguration.ServiceDependencies) { var dependencyProjectName = "AWSSDK." + dependency.Key + "." + projectType; string dependencyProject; if (string.Equals(dependency.Key, "Core", StringComparison.InvariantCultureIgnoreCase)) { dependencyProject = string.Concat(@"..\..\", dependency.Key, "\\", dependencyProjectName, ".csproj"); } else { dependencyProject = string.Concat(@"..\", dependency.Key, "\\", dependencyProjectName, ".csproj"); } projectReferences.Add(new ProjectReference { IncludePath = dependencyProject, ProjectGuid = Utils.GetProjectGuid(Path.Combine(serviceFilesRoot, dependencyProject)), Name = dependencyProjectName }); } } projectProperties.ProjectReferences = projectReferences.OrderBy(x => x.Name).ToList(); if (serviceConfiguration.ReferenceDependencies != null && serviceConfiguration.ReferenceDependencies.ContainsKey(projectFileConfiguration.Name)) { projectProperties.ReferenceDependencies = serviceConfiguration.ReferenceDependencies[projectFileConfiguration.Name]; } GenerateProjectFile(projectFileConfiguration, projectConfigurationData, projectProperties, serviceFilesRoot, projectFilename); } }
/// <summary> /// Creates the platform-specific project files for the given service configuration /// </summary> /// <param name="serviceFilesRoot">The folder under which all of the source files for the service will exist</param> /// <param name="serviceConfiguration"></param> /// <param name="projectFileConfigurations"></param> public void Execute(string serviceFilesRoot, ServiceConfiguration serviceConfiguration, IEnumerable<ProjectFileConfiguration> projectFileConfigurations) { CreatedProjectFiles = new Dictionary<string, ProjectConfigurationData>(); var assemblyName = "AWSSDK." + serviceConfiguration.Namespace.Split('.')[1]; foreach (var projectFileConfiguration in projectFileConfigurations) { if (projectFileConfiguration.IsSubProfile && !(serviceConfiguration.PclVariants != null && serviceConfiguration.PclVariants.Any(p => p.Equals(projectFileConfiguration.Name)))) { // Skip sub profiles for service projects. continue; } var projectType = projectFileConfiguration.Name; if (projectType.Equals("Unity", StringComparison.InvariantCultureIgnoreCase)) { if (!serviceConfiguration.SupportedInUnity) continue; } var projectFilename = string.Concat(assemblyName, ".", projectType, ".csproj"); bool newProject = false; string projectGuid; if (File.Exists(Path.Combine(serviceFilesRoot, projectFilename))) { Console.WriteLine("...updating existing project file {0}", projectFilename); var projectPath = Path.Combine(serviceFilesRoot, projectFilename); projectGuid = Utils.GetProjectGuid(projectPath); } else { newProject = true; projectGuid = Utils.NewProjectGuid; Console.WriteLine("...creating project file {0}", projectFilename); } var templateSession = new Dictionary<string, object>(); templateSession["Name"] = projectFileConfiguration.Name; templateSession["ProjectGuid"] = projectGuid; templateSession["RootNamespace"] = serviceConfiguration.Namespace; templateSession["AssemblyName"] = assemblyName; templateSession["SourceDirectories"] = GetProjectSourceFolders(projectFileConfiguration, serviceFilesRoot); templateSession["NugetPackagesLocation"] = @"..\..\..\packages\"; templateSession["TargetFrameworkVersion"] = projectFileConfiguration.TargetFrameworkVersion; templateSession["DefineConstants"] = projectFileConfiguration.CompilationConstants; templateSession["BinSubfolder"] = projectFileConfiguration.BinSubFolder; var projectConfigurationData = new ProjectConfigurationData { ProjectGuid = projectGuid }; var projectName = Path.GetFileNameWithoutExtension(projectFilename); if (newProject) CreatedProjectFiles[projectName] = projectConfigurationData; var coreRuntimeProject = string.Concat(@"..\..\Core\AWSSDK.Core.", projectType, ".csproj"); var projectReferences = new List<ProjectReference>(); if (serviceConfiguration.ServiceDependencies != null) { foreach (var dependency in serviceConfiguration.ServiceDependencies) { var pt = projectType; if (!(pt.StartsWith(@"Net") || pt.StartsWith(@"Unity")) && serviceConfiguration.UsePclProjectDependencies) pt = @"PCL"; var dependencyProjectName = "AWSSDK." + dependency.Key + "." + pt; string dependencyProject; if (string.Equals(dependency.Key, "Core", StringComparison.InvariantCultureIgnoreCase)) { dependencyProject = string.Concat(@"..\..\", dependency.Key, "\\", dependencyProjectName, ".csproj"); } else { dependencyProject = string.Concat(@"..\", dependency.Key, "\\", dependencyProjectName, ".csproj"); } projectReferences.Add(new ProjectReference { IncludePath = dependencyProject, ProjectGuid = Utils.GetProjectGuid(Path.Combine(serviceFilesRoot, dependencyProject)), Name = dependencyProjectName }); } } templateSession["ProjectReferences"] = projectReferences.OrderBy(x => x.Name).ToList(); templateSession["UnityPath"] = Options.UnityPath; if (serviceConfiguration.ModelName.Equals("s3", StringComparison.OrdinalIgnoreCase) && projectType == "Net45") { templateSession["SystemReferences"] = new List<string> { "System.Net.Http" }; } if (serviceConfiguration.ReferenceDependencies != null && serviceConfiguration.ReferenceDependencies.ContainsKey(projectFileConfiguration.Name)) { templateSession["ReferenceDependencies"] = serviceConfiguration.ReferenceDependencies[projectFileConfiguration.Name]; templateSession["NuGetTargetFramework"] = projectFileConfiguration.NuGetTargetPlatform; } GenerateProjectFile(projectFileConfiguration, projectConfigurationData, templateSession, serviceFilesRoot, projectFilename); } if (serviceConfiguration.CoreCLRSupport) GenerateCoreCLRProjectFiles(serviceFilesRoot, serviceConfiguration, assemblyName); else Console.WriteLine("Skipping CoreCLR support for {0}", serviceConfiguration.BaseName); }
/// <summary> /// Invokes the T4 generator to emit a platform-specific project file. /// </summary> /// <param name="projectFileConfiguration"></param> /// <param name="session"></param> /// <param name="serviceFilesRoot"></param> /// <param name="projectFilename"></param> private void GenerateProjectFile(ProjectFileConfiguration projectFileConfiguration, ProjectConfigurationData projectConfiguration, IDictionary<string, object> session, string serviceFilesRoot, string projectFilename) { var projectName = Path.GetFileNameWithoutExtension(projectFilename); string generatedContent = null; try { var projectTemplateType = Type.GetType( "ServiceClientGenerator.Generators.ProjectFiles." + projectFileConfiguration.Template); dynamic generator = Activator.CreateInstance(projectTemplateType); generator.Session = session; generatedContent = generator.TransformText(); } catch (Exception) { throw new ArgumentException("Project template name " + projectFileConfiguration.Template + " is not recognized"); } GeneratorDriver.WriteFile(serviceFilesRoot, string.Empty, projectFilename, generatedContent); projectConfiguration.ConfigurationPlatforms = projectFileConfiguration.Configurations; }
/// <summary> /// Creates the platform-specific project files for the given service configuration /// </summary> /// <param name="serviceFilesRoot">The folder under which all of the source files for the service will exist</param> /// <param name="serviceConfiguration"></param> /// <param name="projectFileConfigurations"></param> public void Execute(string serviceFilesRoot, ServiceConfiguration serviceConfiguration, IEnumerable<ProjectFileConfiguration> projectFileConfigurations) { CreatedProjectFiles = new Dictionary<string, ProjectConfigurationData>(); foreach (var projectFileConfiguration in projectFileConfigurations) { var projectType = projectFileConfiguration.Name; var assemblyName = "AWSSDK." + serviceConfiguration.Namespace.Split('.')[1]; var projectFilename = string.Concat(assemblyName, ".", projectType, ".csproj"); bool newProject = false; string projectGuid; if (File.Exists(Path.Combine(serviceFilesRoot, projectFilename))) { Console.WriteLine("...updating existing project file {0}", projectFilename); var xdoc = new XmlDocument(); xdoc.Load(Path.Combine(serviceFilesRoot, projectFilename)); var propertyGroups = xdoc.GetElementsByTagName("PropertyGroup"); var element = ((XmlElement)propertyGroups[0]).GetElementsByTagName("ProjectGuid")[0]; if(element == null) { throw new ApplicationException("Failed to find project guid for existing project: " + Path.Combine(serviceFilesRoot, projectFilename)); } projectGuid = element.InnerText; } else { newProject = true; projectGuid = NewProjectGuid; Console.WriteLine("...creating project file {0}", projectFilename); } var templateSession = new Dictionary<string, object>(); templateSession["ProjectGuid"] = projectGuid; templateSession["RootNamespace"] = serviceConfiguration.Namespace; templateSession["AssemblyName"] = assemblyName; templateSession["SourceDirectories"] = GetProjectSourceFolders(projectFileConfiguration, serviceFilesRoot); templateSession["NugetPackagesLocation"] = @"..\..\..\packages\"; templateSession["TargetFrameworkVersion"] = projectFileConfiguration.TargetFrameworkVersion; templateSession["DefineConstants"] = projectFileConfiguration.CompilationConstants; templateSession["BinSubfolder"] = projectFileConfiguration.BinSubFolder; var projectConfigurationData = new ProjectConfigurationData { ProjectGuid = projectGuid }; var projectName = Path.GetFileNameWithoutExtension(projectFilename); if(newProject) CreatedProjectFiles[projectName] = projectConfigurationData; var coreRuntimeProject = string.Concat(@"..\..\Core\AWSSDK.Core.", projectType, ".csproj"); var projectReferences = new List<ProjectReference>(); if (serviceConfiguration.ServiceDependencies != null) { foreach (var dependency in serviceConfiguration.ServiceDependencies) { var dependencyProjectName = "AWSSDK." + dependency.Key + "." + projectType; string dependencyProject; if (string.Equals(dependency.Key, "Core", StringComparison.InvariantCultureIgnoreCase)) { dependencyProject = string.Concat(@"..\..\", dependency.Key, "\\", dependencyProjectName, ".csproj"); } else { dependencyProject = string.Concat(@"..\", dependency.Key, "\\", dependencyProjectName, ".csproj"); } projectReferences.Add(new ProjectReference { IncludePath = dependencyProject, ProjectGuid = ProjectGuidFromFile(Path.Combine(serviceFilesRoot, dependencyProject)), Name = dependencyProjectName }); } } templateSession["ProjectReferences"] = projectReferences.OrderBy(x => x.Name).ToList(); if (serviceConfiguration.ModelName.Equals("s3", StringComparison.OrdinalIgnoreCase) && projectType == "Net45") { templateSession["SystemReferences"] = new List<string> { "System.Net.Http" }; } GenerateProjectFile(projectFileConfiguration, projectConfigurationData, templateSession, serviceFilesRoot, projectFilename); } }
/// <summary> /// Invokes the T4 generator to emit a platform-specific project file. /// </summary> /// <param name="projectFileConfiguration"></param> /// <param name="session"></param> /// <param name="serviceFilesRoot"></param> /// <param name="projectFilename"></param> private void GenerateProjectFile(ProjectFileConfiguration projectFileConfiguration, ProjectConfigurationData projectConfiguration, IDictionary<string, object> session, string serviceFilesRoot, string projectFilename) { var projectName = Path.GetFileNameWithoutExtension(projectFilename); // have not found a reasonable way to be able to activate from a string typename and // cast back to actual generator type instance :-(. Was hoping to make this completely // generic. string generatedContent; switch (projectFileConfiguration.Template) { case "BclProjectFile": { var generator = new BclProjectFile { Session = session }; generatedContent = generator.TransformText(); } break; case "PhoneProjectFile": { var generator = new PhoneProjectFile { Session = session }; generatedContent = generator.TransformText(); } break; case "RtProjectFile": { var generator = new RtProjectFile { Session = session }; generatedContent = generator.TransformText(); } break; case "PortableProjectFile": { var generator = new PortableProjectFile { Session = session }; generatedContent = generator.TransformText(); } break; default: throw new ArgumentException("Project template name " + projectFileConfiguration.Template + " is not recognized"); } GeneratorDriver.WriteFile(serviceFilesRoot, string.Empty, projectFilename, generatedContent); projectConfiguration.ConfigurationPlatforms = projectFileConfiguration.Configurations; }