ServiceClientGenerator.ProjectFileCreator.Execute C# (CSharp) Method

Execute() public method

Creates the platform-specific project files for the given service configuration
public Execute ( string serviceFilesRoot, ServiceConfiguration serviceConfiguration, IEnumerable projectFileConfigurations ) : void
serviceFilesRoot string The folder under which all of the source files for the service will exist
serviceConfiguration ServiceConfiguration
projectFileConfigurations IEnumerable
return void
        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);
        }

Usage Example

Esempio n. 1
0
 /// <summary>
 /// Generates any missing project files for a service
 /// </summary>
 void ExecuteProjectFileGenerators()
 {
     var creator = new ProjectFileCreator();
     creator.Execute(ServiceFilesRoot, this.Configuration, this.ProjectFileConfigurations);
     foreach (var newProjectKey in creator.CreatedProjectFiles.Keys)
     {
         NewlyCreatedProjectFiles.Add(newProjectKey, creator.CreatedProjectFiles[newProjectKey]);
     }
 }