From f24c74a3cc9d8c51e7af6c8f03eb113191fcec8c Mon Sep 17 00:00:00 2001 From: itn3000 Date: Fri, 12 Oct 2018 18:29:31 +0900 Subject: [PATCH] update to buildalyzer-2.1.0 * add github deployment and artifact * merge appveyor setting file for Release --- appveyor-release.yml | 16 ----- appveyor.yml | 25 ++++++- src/mo-gen/Program.cs | 5 +- src/mo-gen/Utils/RoslynExtensions.cs | 66 +++++++++---------- src/mo-gen/mo-gen.csproj | 17 ++--- .../mo_gen_test_project.csproj | 2 +- 6 files changed, 66 insertions(+), 65 deletions(-) delete mode 100644 appveyor-release.yml diff --git a/appveyor-release.yml b/appveyor-release.yml deleted file mode 100644 index e690110..0000000 --- a/appveyor-release.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: 1.0.{build} -skip_non_tags: true -init: - - git config --global core.autocrlf input -configuration: Release -image: Visual Studio 2017 -build: - project: mo-gen.sln - publish_nuget: true - publish_nuget_symbols: true -install: - - dotnet restore -deploy: -- provider: NuGet - api_key: - secure: F67S4wlZEdRiowy0DR25bnfszCdcNsO3R6ykHeGTWEsl6iqXUJEx+W4M6tk6+iVP \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 5879761..5dde583 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,4 @@ version: 1.0.{build} -skip_tags: true init: - git config --global core.autocrlf input configuration: Release @@ -8,5 +7,27 @@ build: project: mo-gen.sln publish_nuget: true publish_nuget_symbols: true +after_build: + pwsh: dotnet pack src/mo-gen/mo-gen.csproj +artifacts: + - path: "**/*.nupkg" + name: NuGetPackages install: - - dotnet restore \ No newline at end of file + - dotnet restore +deploy: +- provider: NuGet + api_key: + secure: F67S4wlZEdRiowy0DR25bnfszCdcNsO3R6ykHeGTWEsl6iqXUJEx+W4M6tk6+iVP + on: + APPVEYOR_REPO_TAG: true + branch: master + artifact: NuGetPackages +- provider: GitHub + auth_token: + secure: MFZg3Ryx8cZ9XWIf8qvSE+48pmQc2LPAcPiRQ7bUtPRKj4mXvn+mtZVzPV7tQyX1 + on: + APPVEYOR_REPO_TAG: true + branch: master + artifact: NuGetPackages + prerelease: false + draft: true \ No newline at end of file diff --git a/src/mo-gen/Program.cs b/src/mo-gen/Program.cs index 42d9d6b..2bb9793 100644 --- a/src/mo-gen/Program.cs +++ b/src/mo-gen/Program.cs @@ -42,7 +42,7 @@ public CommandlineArguments(string[] args) { "n|namespace=", "[optional, default=MagicOnion]Set namespace root name", x => { NamespaceRoot = x; } }, { "a|asyncsuffix", "[optional, default=false]Use methodName to async suffix", _ => { IsAsyncSuffix = true; } }, { "c|conditionalsymbol=", "[optional, default=empty]conditional compiler symbol list separated by ','", x => ConditionalSymbols.AddRange(x.Split(",")) }, - { "v|verbose=", "[optional, default=None]project compilation output verbosity level(None,Minimal,Normal,Detailed)", level => { + { "v|verbose=", "[optional, default=None]project compilation output verbosity level(None,Minimal,Normal,Detailed,Diagnostic)", level => { switch(level.ToLower()) { case "none": @@ -57,6 +57,9 @@ public CommandlineArguments(string[] args) case "detailed": VerbosityLevel = 3; break; + case "diagnostic": + VerbosityLevel = 4; + break; default: break; } diff --git a/src/mo-gen/Utils/RoslynExtensions.cs b/src/mo-gen/Utils/RoslynExtensions.cs index 998271f..f804138 100644 --- a/src/mo-gen/Utils/RoslynExtensions.cs +++ b/src/mo-gen/Utils/RoslynExtensions.cs @@ -11,8 +11,10 @@ using System.Xml.Linq; using MagicOnion.Utils; using Buildalyzer; +using Buildalyzer.Environment; using Microsoft.Build.Utilities; using Microsoft.Build.Framework; +using MsLogging = Microsoft.Extensions.Logging; namespace MagicOnion { @@ -29,6 +31,8 @@ static LoggerVerbosity ToLoggerVerbosity(this int value) return LoggerVerbosity.Normal; case 3: return LoggerVerbosity.Detailed; + case 4: + return LoggerVerbosity.Diagnostic; case 0: default: return LoggerVerbosity.Quiet; @@ -77,10 +81,16 @@ static LanguageVersion ConvertLanguageVersion(string versionString) return LanguageVersion.Default; } } + public static async Task GetCompilationFromProject(string csprojPath, int verbosityLevel, Dictionary additionalProperties, IEnumerable conditionalSymbols) { + conditionalSymbols = conditionalSymbols != null ? + conditionalSymbols.Where(x => !string.IsNullOrEmpty(x)).ToArray() + : + Enumerable.Empty(); + // fucking workaround of resolve reference... var externalReferences = new List(); { @@ -119,57 +129,45 @@ public static async Task GetCompilationFromProject(string csprojPat EnvironmentHelper.Setup(); var analyzerOptions = new AnalyzerManagerOptions(); - analyzerOptions.LoggerVerbosity = verbosityLevel.ToLoggerVerbosity(); if (verbosityLevel > 0) { analyzerOptions.LogWriter = Console.Out; } var manager = new AnalyzerManager(analyzerOptions); var projectAnalyzer = manager.GetProject(csprojPath); + projectAnalyzer.AddBuildLogger(new Microsoft.Build.Logging.ConsoleLogger(verbosityLevel.ToLoggerVerbosity())); + var buildopts = new EnvironmentOptions(); if (additionalProperties != null) { foreach (var kv in additionalProperties) { + buildopts.GlobalProperties[kv.Key] = kv.Value; projectAnalyzer.SetGlobalProperty(kv.Key, kv.Value); } } - var compiledProject = projectAnalyzer.Build().Project; - var ws = new AdhocWorkspace(); - if (compiledProject == null) + if (conditionalSymbols.Any()) { - throw new Exception("project compilation failed"); + buildopts.GlobalProperties["DefineConstants"] = string.Join("%3b", conditionalSymbols); } - - var workspace = projectAnalyzer.GetWorkspace(); - workspace.WorkspaceFailed += WorkSpaceFailed; - var project = workspace.CurrentSolution.Projects.First(); - project = project.AddMetadataReferences(externalReferences); - var opt = project.ParseOptions as CSharpParseOptions; - if (opt != null) + var analyzerResults = projectAnalyzer.Build(buildopts); + var analyzerResult = analyzerResults.FirstOrDefault(x => x.Succeeded); + if (analyzerResult == null) { - var defineconstants = compiledProject.GetPropertyValue("DefineConstants").Split(';'); - var langVersion = compiledProject.GetPropertyValue("LangVersion"); - var features = compiledProject.GetPropertyValue("Features").Split(';').Select(x => - { - var kv = x.Split('=', 2); - if (kv.Length == 1) - { - return new KeyValuePair(kv[0], "true"); - } - else if (kv.Length > 1) - { - return new KeyValuePair(kv[0], kv[1]); - } - else - { - return new KeyValuePair(null, null); - } - }).Where(x => x.Key != null).ToArray(); - opt = opt.WithLanguageVersion(ConvertLanguageVersion(langVersion)) - .WithPreprocessorSymbols(defineconstants.Concat(conditionalSymbols)) - .WithFeatures(features) + throw new Exception("no succeeded analyzer result found"); + } + var ws = new AdhocWorkspace(); + var project = analyzerResult.AddToWorkspace(ws); + var parseopts = project.ParseOptions as CSharpParseOptions; + if (parseopts != null) + { + var symbols = analyzerResult.Properties.ContainsKey("DefineConstants") ? + conditionalSymbols.Concat( + analyzerResult.Properties["DefineConstants"].Split(';') + ).OrderBy(x => x).Distinct() + : + conditionalSymbols ; - project = project.WithParseOptions(opt); + project = project.WithParseOptions(parseopts.WithPreprocessorSymbols(symbols)); } var compilation = await project.GetCompilationAsync().ConfigureAwait(false); return compilation; diff --git a/src/mo-gen/mo-gen.csproj b/src/mo-gen/mo-gen.csproj index da561af..c7456f2 100644 --- a/src/mo-gen/mo-gen.csproj +++ b/src/mo-gen/mo-gen.csproj @@ -7,10 +7,10 @@ true true dotnet-mo-gen - 0.1.1 + 0.2.0 - 0.1.1 + 0.2.0 dotnet-mo-gen Unity client code generator for MagicOnion skitoy4321 @@ -23,15 +23,10 @@ - - - - - - - - - + + + + diff --git a/test/mo_gen_test_project/mo_gen_test_project.csproj b/test/mo_gen_test_project/mo_gen_test_project.csproj index 2d1948f..a262d55 100644 --- a/test/mo_gen_test_project/mo_gen_test_project.csproj +++ b/test/mo_gen_test_project/mo_gen_test_project.csproj @@ -8,7 +8,7 @@ - +