using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Json.LitJson; namespace ServiceClientGenerator { /// /// Represents the metadata needed to generate a platform-specific project file /// for a service (eg compile constants, build configuration and platform etc). /// public class ProjectFileConfiguration { /// /// The name of the platform configuration; this forms part of the project /// filename. /// public string Name { get; set; } /// /// The set of solution build configuration and platforms (eg Debug|Any CPU) /// supported by the project kind. /// public IEnumerable Configurations { get; set; } /// /// The .Net Framework versions, in format vX.Y, that the project will compile /// against. /// public IEnumerable TargetFrameworkVersions { get; set; } /// /// The #define constants to be set at compile time. These are used for all /// compilation types (debug, release etc). /// public IEnumerable CompilationConstants { get; set; } /// /// The name of the subfolder that the compile outputs should be placed into. /// By convention this is the same as the Name property, but lowercase. /// public string BinSubFolder { get; set; } /// /// The name of the T4 generator file used to emit the project file. The /// type name should be relative to the code generator's Generators /// namespace. /// public string Template { get; set; } /// /// The set of subfolder names used to hold custom code for a platform /// public IEnumerable PlatformCodeFolders { get; set; } public IEnumerable PlatformExcludeFolders { get; set; } /// /// The platform name used by NuGet (e.g. wpa81) /// public string NuGetTargetPlatform { get; set; } /// /// The set of projects that should be included in the solution test folder. /// public IEnumerable ExtraTestProjects { get; set; } /// /// Returns true if the last component of the specified folder /// path begins with '_' character, our convention for representing /// platform-specific code. /// public bool IsPlatformCodeFolder(string sourceFolder) { return GetPlatformFolderName(sourceFolder) != null; } public IEnumerable ProjectReferences { get; set; } public IEnumerable EmbeddedResources { get; set; } public IEnumerable VisualStudioServices { get; set; } public string NoWarn { get; set; } public string OutputPathOverride { get; set; } public List PackageReferences { get; set; } /// /// Specify where the framework binaries are. For net35 in vs2017 project, this is needed /// to work around https://github.com/Microsoft/msbuild/issues/1333 /// public string FrameworkPathOverride { get; set; } public IEnumerable DllReferences { get; set; } /// /// Returns true if the specified folder ends with one of the custom code /// platform folder names declared for this configuration. /// /// /// private string GetPlatformFolderName(string folder) { var tokens = folder.Split('\\'); string platformFolder = null; for (int i = tokens.Length - 1; i >= 0; i--) { if (tokens[i].StartsWith("_")) { platformFolder = tokens[i]; break; } } return platformFolder; } /// /// Returns true if the specified path folder names conforms with the /// platform folder names declared for this configuration. /// /// /// public bool IsValidPlatformPathForProject(string sourceFolder) { var tokens = sourceFolder.Split(new[] { Path.AltDirectorySeparatorChar }); if (PlatformCodeFolders.Any()) { foreach(var folder in tokens) { if (folder.StartsWith("_")) { bool isValid = false; foreach (var pcf in PlatformCodeFolders) { if (folder.Equals(pcf, StringComparison.OrdinalIgnoreCase)) { isValid = true; break; } } if (!isValid) { return false; } } } } return true; } } }