public void Write() { TemplatedWriter propsWriter = new TemplatedWriter(propsTemplateFile) .Write(ProjectGuidToken, Guid) .Write(MSBuildForUnityVersionToken, MSBuildForUnityVersion.ToString()); foreach (ProjectReference projectReference in References) { TemplatedWriter referenceWriter = propsWriter.CreateWriterFor(ProjectReferenceTemplate) .Write(ProjectReferenceTemplate_ReferenceToken, projectReference.ReferencePath.LocalPath) .Write(ProjectReferenceTemplate_ConditionToken, projectReference.Condition ?? string.Empty); if (projectReference.IsGenerated) { // Creating this is sufficient for the template to be included in the output referenceWriter.CreateWriterFor(PrivateReferenceTemplate); } } propsWriter.Export(propsExportPath); // Don't overwrite primary export path, as that is the file that is allowed to be edited if (!File.Exists(primaryExportPath.FullName)) { new TemplatedWriter(primaryTemplateFile).Export(primaryExportPath); } new TemplatedWriter(targetsTemplateFile).Export(targetsExportPath); }
protected override void OnWrite(TemplatedWriter writer) { base.OnWrite(writer); writer.Write(TargetUWPVersionToken, TargetUWPVersion); writer.Write(MinimumUWPVersionToken, MinimumUWPVersion); }
private void WriteDictionarySet(TemplatedWriter writer, IDictionary <string, string> set, string template) { foreach (KeyValuePair <string, string> pair in set) { writer.CreateWriterFor(template) .Write(KeyValueTemplate_KeyToken, pair.Key) .Write(KeyValueTemplate_ValueToken, pair.Value); } }
public void Write() { TemplatedWriter writer = new TemplatedWriter(solutionFileTemplate); // Validate configuration, to ensure the solution has all of the children mapping ValidateProjectConfiguration(); // Write out Project Data foreach (Guid projectGuid in GetOrderedProjects()) { WriteProject(writer, projectGuid, Projects[projectGuid]); } SortedDictionary <Guid, Guid> childToParentMapping = new SortedDictionary <Guid, Guid>(); // Write folders foreach (KeyValuePair <Guid, SolutionFolder> folder in Folders) { writer.CreateWriterFor(FolderTemplate) .Write(FolderTemplate_GuidToken, folder.Key) .Write(FolderTemplate_NameToken, folder.Value.Name); foreach (Guid child in folder.Value.Children) { childToParentMapping[child] = folder.Key; } } // Write the sorted nested projects foreach (KeyValuePair <Guid, Guid> mapping in childToParentMapping) { writer.CreateWriterFor(FolderNestedTemplate) .Write(FolderNestedTemplate_ChildGuidToken, mapping.Key) .Write(FolderNestedTemplate_FolderGuidToken, mapping.Value); } // Write Config mappings foreach (ConfigurationPlatformPair configPair in ConfigurationPlatforms) { writer.CreateWriterFor(ConfigurationPlatformTemplate) .Write(ConfigurationPlatformTemplate_ConfigurationToken, configPair.Configuration) .Write(ConfigurationPlatformTemplate_PlatformToken, configPair.Platform); } // Write generated items WriteDictionarySet(writer, GeneratedItems.ToDictionary(guid => $"{{{guid}}}", t => MSB4UGeneratedNote), SolutionNotesTemplate); // Write all the known dictionary sections WriteDictionarySet(writer, Properties, SolutionPropertiesTemplate); WriteDictionarySet(writer, Notes, SolutionNotesTemplate); WriteDictionarySet(writer, ExtensibilityGlobals, ExtensibilityGlobalsTemplate); // Write Extra sections WriteExtraSections(writer, AdditionalSections, KnownSolutionSectionNames, ExtraGlobalSectionTemplate, t => t == SectionType.PreSection ? "preSolution" : "postSolution"); writer.Export(solutionOutputPath); }
private void WriteConfigurationProperty(TemplatedWriter solutionWriter, Guid projectGuid, ConfigurationPlatformPair solutionPair, string property, ConfigurationPlatformPair projectPair) { solutionWriter.CreateWriterFor(ProjectConfigurationPlatformPropertyTemplate) .Write(ProjectConfigurationPlatformPropertyTemplate_ProjectGuidToken, projectGuid) .Write(ProjectConfigurationPlatformPropertyTemplate_SolutionConfigurationToken, solutionPair.Configuration) .Write(ProjectConfigurationPlatformPropertyTemplate_SolutionPlatformToken, solutionPair.Platform) .Write(ProjectConfigurationPlatformPropertyTemplate_PropertyToken, property) .Write(ProjectConfigurationPlatformPropertyTemplate_ProjectConfigurationToken, projectPair.Configuration) .Write(ProjectConfigurationPlatformPropertyTemplate_ProjectPlatformToken, projectPair.Platform); }
public void Write() { TemplatedWriter writer = new TemplatedWriter(fileTemplate); writer.Write(MSBuildForUnityVersionToken, MSBuildForUnityVersion.ToString()); writer.Write(UnityMajorVersionToken, UnityMajorVersion); writer.Write(UnityMinorVersionToken, UnityMinorVersion); writer.Write(UnityEditorInstallPathToken, UnityEditorInstallPath.FullName); writer.Write(CurrentUnityPlatformToken, CurrentUnityPlatform); writer.Write(CurrentTargetFrameworkToken, CurrentTargetFramework); writer.Write(UnityProjectAssetsDirectoryToken, UnityProjectAssetsDirectory.FullName); writer.Write(GeneratedOutputDirectoryToken, GeneratedProjectOutputPath.FullName); writer.Export(exportPath); }
private void WriteProject(TemplatedWriter solutionWriter, Guid projectGuid, SolutionProject project) { TemplatedWriter projectWriter = solutionWriter.CreateWriterFor(ProjectTemplate) .Write(ProjectTemplate_ProjectTypeGuidToken, project.TypeGuid) .Write(ProjectTemplate_NameToken, project.Name) .Write(ProjectTemplate_RelativePathToken, project.RelativePath.IsAbsoluteUri ? project.RelativePath.LocalPath : project.RelativePath.AsRelativePath()) .Write(ProjectTemplate_GuidToken, projectGuid); if (project.Dependencies.Count > 0) { TemplatedWriter dependencyWriter = projectWriter.CreateWriterFor(ProjectTemplate_ProjectSection); foreach (Guid dependency in project.Dependencies) { dependencyWriter .CreateWriterFor(ProjectTemplate_ProjectSection_DependencyTemplate) .Write(ProjectTemplate_ProjectSection_DependencyTemplate_DependencyGuidToken, dependency); } } foreach (ConfigurationPlatformPair configPlatform in ConfigurationPlatforms) { ProjectConfigurationPlatformMapping mapping = project.ConfigurationPlatformMapping[configPlatform]; WriteConfigurationProperty(solutionWriter, projectGuid, configPlatform, "ActiveCfg", mapping.ConfigurationPlatform); if (mapping.EnabledForBuild) { WriteConfigurationProperty(solutionWriter, projectGuid, configPlatform, "Build.0", mapping.ConfigurationPlatform); } if (mapping.AdditionalPropertyMappings != null) { foreach (KeyValuePair <string, ConfigurationPlatformPair> propertyPair in mapping.AdditionalPropertyMappings) { if (KnownConfiguationPlatformProperties.Contains(propertyPair.Key)) { logger?.LogError(nameof(TemplatedSolutionExporter), $"Can't export '{propertyPair.Key}' as a property for project '{project.Name}' {configPlatform.Configuration}|{configPlatform.Platform}, as it's a known property."); } else { WriteConfigurationProperty(solutionWriter, projectGuid, configPlatform, propertyPair.Key, propertyPair.Value); } } } } WriteExtraSections(projectWriter, project.AdditionalSections, KnownProjectSectionNames, ExtraProjectSectionTemplate, t => t == SectionType.PreSection ? "preProject" : "postProject"); }
public void Write() { TemplatedWriter writer = new TemplatedWriter(fileTemplate); writer.Write(TargetFrameworkToken, TargetFramework, optional: true); writer.Write(DefineConstantsToken, DefineConstants); writer.Write(AssemblySearchPathsToken, AssemblySearchPaths); foreach (KeyValuePair <string, Uri> reference in References) { TemplatedWriter subTemplateWriter = writer.CreateWriterFor(CommonReferenceSubTemplate); subTemplateWriter.Write(CommonReferencesSubTemplateReferenceToken, reference.Key); subTemplateWriter.Write(CommonReferencesSubTemplateHintPathToken, reference.Value.LocalPath); } OnWrite(writer); writer.Export(exportPath); }
private void WriteExtraSections(TemplatedWriter writer, IDictionary <string, SolutionSection> sections, ISet <string> knownSections, string sectionTemplate, Func <SectionType, string> sectionTypeToString) { foreach (KeyValuePair <string, SolutionSection> section in sections) { if (knownSections.Contains(section.Key)) { logger?.LogError(nameof(TemplatedSolutionExporter), $"Can't export '{section.Key}' as an additional section, as it's a known section."); } else { TemplatedWriter extraProjectSectionWriter = writer.CreateWriterFor(sectionTemplate) .Write(ExtraSectionTemplate_SectionNameToken, section.Key) .Write(ExtraSectionTemplate_SectionTypeToken, sectionTypeToString(section.Value.Type)); foreach (string line in section.Value.SectionLines) { extraProjectSectionWriter.CreateWriterFor(ExtraSectionTemplate_LineTemplate) .Write(ExtraSectionTemplate_LineTemplate_LineToken, line); } } } }
public void Write() { TemplatedWriter propsWriter = new TemplatedWriter(propsTemplateFile) .Write(ProjectGuidToken, Guid) .Write(ProjectNameToken, ProjectName) .Write(AllowUnsafeToken, AllowUnsafe.ToString()) .Write(LanguageVersionToken, LanguageVersion) .Write(IsEditorOnlyProjectToken, IsEditorOnlyProject.ToString()) .Write(DefaultPlatformToken, DefaultPlatform) .Write(SupportedPlatformsToken, SupportedPlatforms) .Write(AssemblySearchPathsToken, AssemblySearchPaths) .Write(SourceIncludePathToken, SourceIncludePath.FullName); foreach (DirectoryInfo excludePath in SourceExcludePaths) { propsWriter.CreateWriterFor(SourceExcludeTemplate) .Write(SourceExcludeTemplate_ExcludePathToken, excludePath.FullName); } foreach (KeyValuePair <UnityConfigurationType, HashSet <PluginReference> > configSet in PluginReferences) { TemplatedWriter setWriter = propsWriter.CreateWriterFor(PluginReferenceTemplateSet) .Write(ReferenceTemplateSet_ConfigurationToken, configSet.Key.ToString()); foreach (PluginReference pluginReference in configSet.Value) { setWriter.CreateWriterFor(PluginReferenceTemplate) .Write(PluginReferenceTemplate_ReferenceToken, pluginReference.ReferenceName) .Write(PluginReferenceTemplate_ConditionToken, pluginReference.Condition) .Write(PluginReferenceTemplate_HintPathToken, pluginReference.HintPath.LocalPath); } } foreach (KeyValuePair <UnityConfigurationType, HashSet <ProjectReference> > configSet in ProjectReferences) { TemplatedWriter setWriter = propsWriter.CreateWriterFor(ProjectReferenceTemplateSet) .Write(ReferenceTemplateSet_ConfigurationToken, configSet.Key.ToString()); foreach (ProjectReference pluginReference in configSet.Value) { setWriter.CreateWriterFor(ProjectReferenceTemplate) .Write(PluginReferenceTemplate_ReferenceToken, pluginReference.ReferencePath.LocalPath) .Write(PluginReferenceTemplate_ConditionToken, pluginReference.Condition); } } propsWriter.Export(propsExportPath); // Write the targets part TemplatedWriter targetsWriter = new TemplatedWriter(targetsTemplateFile); foreach (ConfigurationPlatformPair pair in SupportedBuildPlatforms) { targetsWriter.CreateWriterFor(SupportedPlatformBuildTemplate) .Write(SupportedPlatformBuildTemplate_ConfigurationToken, pair.Configuration) .Write(SupportedPlatformBuildTemplate_PlatformToken, pair.Platform); } targetsWriter.Export(targetsExportPath); // Don't overwrite primary export path, as that is the file that is allowed to be edited if (IsGenerated) { new TemplatedWriter(primaryTemplateFile).Export(primaryExportPath); File.SetAttributes(primaryExportPath.FullName, FileAttributes.ReadOnly); } else if (!File.Exists(primaryExportPath.FullName)) { new TemplatedWriter(primaryTemplateFile).Export(primaryExportPath); } }
protected virtual void OnWrite(TemplatedWriter writer) { }
/// <summary> /// Updates the value of the field and the token (if the field has changed). /// </summary> /// <param name="writer">The "this" writer.</param> /// <param name="token">The token key.</param> /// <param name="value">The Guid to update to.</param> /// <param name="optional">Whether this is an optional setting.</param> /// <returns>The same writer to allow chaining of writes.</returns> internal static TemplatedWriter Write(this TemplatedWriter writer, string token, Guid guid, bool optional = false) { return(writer.Write(token, guid.ToString().ToUpper(), optional: optional)); }