Skip to content
This repository was archived by the owner on Jan 10, 2019. It is now read-only.

Commit f24c74a

Browse files
committed
update to buildalyzer-2.1.0
* add github deployment and artifact * merge appveyor setting file for Release
1 parent 39cd006 commit f24c74a

File tree

6 files changed

+66
-65
lines changed

6 files changed

+66
-65
lines changed

appveyor-release.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

appveyor.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
version: 1.0.{build}
2-
skip_tags: true
32
init:
43
- git config --global core.autocrlf input
54
configuration: Release
@@ -8,5 +7,27 @@ build:
87
project: mo-gen.sln
98
publish_nuget: true
109
publish_nuget_symbols: true
10+
after_build:
11+
pwsh: dotnet pack src/mo-gen/mo-gen.csproj
12+
artifacts:
13+
- path: "**/*.nupkg"
14+
name: NuGetPackages
1115
install:
12-
- dotnet restore
16+
- dotnet restore
17+
deploy:
18+
- provider: NuGet
19+
api_key:
20+
secure: F67S4wlZEdRiowy0DR25bnfszCdcNsO3R6ykHeGTWEsl6iqXUJEx+W4M6tk6+iVP
21+
on:
22+
APPVEYOR_REPO_TAG: true
23+
branch: master
24+
artifact: NuGetPackages
25+
- provider: GitHub
26+
auth_token:
27+
secure: MFZg3Ryx8cZ9XWIf8qvSE+48pmQc2LPAcPiRQ7bUtPRKj4mXvn+mtZVzPV7tQyX1
28+
on:
29+
APPVEYOR_REPO_TAG: true
30+
branch: master
31+
artifact: NuGetPackages
32+
prerelease: false
33+
draft: true

src/mo-gen/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public CommandlineArguments(string[] args)
4242
{ "n|namespace=", "[optional, default=MagicOnion]Set namespace root name", x => { NamespaceRoot = x; } },
4343
{ "a|asyncsuffix", "[optional, default=false]Use methodName to async suffix", _ => { IsAsyncSuffix = true; } },
4444
{ "c|conditionalsymbol=", "[optional, default=empty]conditional compiler symbol list separated by ','", x => ConditionalSymbols.AddRange(x.Split(",")) },
45-
{ "v|verbose=", "[optional, default=None]project compilation output verbosity level(None,Minimal,Normal,Detailed)", level => {
45+
{ "v|verbose=", "[optional, default=None]project compilation output verbosity level(None,Minimal,Normal,Detailed,Diagnostic)", level => {
4646
switch(level.ToLower())
4747
{
4848
case "none":
@@ -57,6 +57,9 @@ public CommandlineArguments(string[] args)
5757
case "detailed":
5858
VerbosityLevel = 3;
5959
break;
60+
case "diagnostic":
61+
VerbosityLevel = 4;
62+
break;
6063
default:
6164
break;
6265
}

src/mo-gen/Utils/RoslynExtensions.cs

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
using System.Xml.Linq;
1212
using MagicOnion.Utils;
1313
using Buildalyzer;
14+
using Buildalyzer.Environment;
1415
using Microsoft.Build.Utilities;
1516
using Microsoft.Build.Framework;
17+
using MsLogging = Microsoft.Extensions.Logging;
1618

1719
namespace MagicOnion
1820
{
@@ -29,6 +31,8 @@ static LoggerVerbosity ToLoggerVerbosity(this int value)
2931
return LoggerVerbosity.Normal;
3032
case 3:
3133
return LoggerVerbosity.Detailed;
34+
case 4:
35+
return LoggerVerbosity.Diagnostic;
3236
case 0:
3337
default:
3438
return LoggerVerbosity.Quiet;
@@ -77,10 +81,16 @@ static LanguageVersion ConvertLanguageVersion(string versionString)
7781
return LanguageVersion.Default;
7882
}
7983
}
84+
8085
public static async Task<Compilation> GetCompilationFromProject(string csprojPath, int verbosityLevel,
8186
Dictionary<string, string> additionalProperties,
8287
IEnumerable<string> conditionalSymbols)
8388
{
89+
conditionalSymbols = conditionalSymbols != null ?
90+
conditionalSymbols.Where(x => !string.IsNullOrEmpty(x)).ToArray()
91+
:
92+
Enumerable.Empty<string>();
93+
8494
// fucking workaround of resolve reference...
8595
var externalReferences = new List<PortableExecutableReference>();
8696
{
@@ -119,57 +129,45 @@ public static async Task<Compilation> GetCompilationFromProject(string csprojPat
119129

120130
EnvironmentHelper.Setup();
121131
var analyzerOptions = new AnalyzerManagerOptions();
122-
analyzerOptions.LoggerVerbosity = verbosityLevel.ToLoggerVerbosity();
123132
if (verbosityLevel > 0)
124133
{
125134
analyzerOptions.LogWriter = Console.Out;
126135
}
127136
var manager = new AnalyzerManager(analyzerOptions);
128137
var projectAnalyzer = manager.GetProject(csprojPath);
138+
projectAnalyzer.AddBuildLogger(new Microsoft.Build.Logging.ConsoleLogger(verbosityLevel.ToLoggerVerbosity()));
139+
var buildopts = new EnvironmentOptions();
129140
if (additionalProperties != null)
130141
{
131142
foreach (var kv in additionalProperties)
132143
{
144+
buildopts.GlobalProperties[kv.Key] = kv.Value;
133145
projectAnalyzer.SetGlobalProperty(kv.Key, kv.Value);
134146
}
135147
}
136-
var compiledProject = projectAnalyzer.Build().Project;
137-
var ws = new AdhocWorkspace();
138-
if (compiledProject == null)
148+
if (conditionalSymbols.Any())
139149
{
140-
throw new Exception("project compilation failed");
150+
buildopts.GlobalProperties["DefineConstants"] = string.Join("%3b", conditionalSymbols);
141151
}
142-
143-
var workspace = projectAnalyzer.GetWorkspace();
144-
workspace.WorkspaceFailed += WorkSpaceFailed;
145-
var project = workspace.CurrentSolution.Projects.First();
146-
project = project.AddMetadataReferences(externalReferences);
147-
var opt = project.ParseOptions as CSharpParseOptions;
148-
if (opt != null)
152+
var analyzerResults = projectAnalyzer.Build(buildopts);
153+
var analyzerResult = analyzerResults.FirstOrDefault(x => x.Succeeded);
154+
if (analyzerResult == null)
149155
{
150-
var defineconstants = compiledProject.GetPropertyValue("DefineConstants").Split(';');
151-
var langVersion = compiledProject.GetPropertyValue("LangVersion");
152-
var features = compiledProject.GetPropertyValue("Features").Split(';').Select(x =>
153-
{
154-
var kv = x.Split('=', 2);
155-
if (kv.Length == 1)
156-
{
157-
return new KeyValuePair<string, string>(kv[0], "true");
158-
}
159-
else if (kv.Length > 1)
160-
{
161-
return new KeyValuePair<string, string>(kv[0], kv[1]);
162-
}
163-
else
164-
{
165-
return new KeyValuePair<string, string>(null, null);
166-
}
167-
}).Where(x => x.Key != null).ToArray();
168-
opt = opt.WithLanguageVersion(ConvertLanguageVersion(langVersion))
169-
.WithPreprocessorSymbols(defineconstants.Concat(conditionalSymbols))
170-
.WithFeatures(features)
156+
throw new Exception("no succeeded analyzer result found");
157+
}
158+
var ws = new AdhocWorkspace();
159+
var project = analyzerResult.AddToWorkspace(ws);
160+
var parseopts = project.ParseOptions as CSharpParseOptions;
161+
if (parseopts != null)
162+
{
163+
var symbols = analyzerResult.Properties.ContainsKey("DefineConstants") ?
164+
conditionalSymbols.Concat(
165+
analyzerResult.Properties["DefineConstants"].Split(';')
166+
).OrderBy(x => x).Distinct()
167+
:
168+
conditionalSymbols
171169
;
172-
project = project.WithParseOptions(opt);
170+
project = project.WithParseOptions(parseopts.WithPreprocessorSymbols(symbols));
173171
}
174172
var compilation = await project.GetCompilationAsync().ConfigureAwait(false);
175173
return compilation;

src/mo-gen/mo-gen.csproj

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
<IsPackable>true</IsPackable>
88
<PackAsTool>true</PackAsTool>
99
<AssemblyName>dotnet-mo-gen</AssemblyName>
10-
<VersionPrefix>0.1.1</VersionPrefix>
10+
<VersionPrefix>0.2.0</VersionPrefix>
1111
</PropertyGroup>
1212
<PropertyGroup>
13-
<PackageVersion>0.1.1</PackageVersion>
13+
<PackageVersion>0.2.0</PackageVersion>
1414
<PackageId>dotnet-mo-gen</PackageId>
1515
<Title>Unity client code generator for MagicOnion</Title>
1616
<Authors>skitoy4321</Authors>
@@ -23,15 +23,10 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<PackageReference Include="Buildalyzer" Version="1.0.0" />
27-
<PackageReference Include="Buildalyzer.Workspaces" Version="1.0.0" />
28-
<PackageReference Include="Microsoft.Build" Version="15.8.166" />
29-
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.8.166" />
30-
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="15.8.166" />
31-
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.8.2" />
32-
<PackageReference Include="Nuget.Frameworks" Version="4.8.0" />
33-
<PackageReference Include="NuGet.Common" Version="4.8.0" />
34-
<PackageReference Include="NuGet.ProjectModel" Version="4.8.0" />
26+
<PackageReference Include="Buildalyzer" Version="2.1.0" />
27+
<PackageReference Include="Buildalyzer.Workspaces" Version="2.1.0" />
28+
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.9.0" />
29+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
3530
<PackageReference Include="System.CodeDom" Version="4.5.0" />
3631
</ItemGroup>
3732

test/mo_gen_test_project/mo_gen_test_project.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="MagicOnion" Version="0.5.2" />
11+
<PackageReference Include="MagicOnion" Version="0.5.3" />
1212
</ItemGroup>
1313

1414
</Project>

0 commit comments

Comments
 (0)