Add support for Platform and allow partial success when generating stubs

Instead of failing the subs generation when the workspace has errors,
ignore projects that don't open.

Resolves #37
This commit is contained in:
Nehme Bilal 2018-03-02 14:41:40 -08:00
Родитель e145b124e5
Коммит 00f6b4c3f3
5 изменённых файлов: 17 добавлений и 7 удалений

Просмотреть файл

@ -2,7 +2,7 @@
<package >
<metadata>
<id>Etg.SimpleStubs</id>
<version>2.4.2</version>
<version>2.4.3</version>
<title>SimpleStubs Mocking Framework (C#).</title>
<authors>Nehme Bilal</authors>
<owners>Microsoft</owners>

Просмотреть файл

@ -15,7 +15,7 @@
<Exec
WorkingDirectory="$(ProjectDir)"
Command="$(MSBuildThisFileDirectory)\..\tools\Etg.SimpleStubs.CodeGen.exe -ProjectPath:&quot;$(ProjectDir)$(ProjectName).csproj&quot; -OutputPath:&quot;$(SimpleStubsCodeGenOutput)&quot; -Configuration:&quot;$(Configuration)&quot;" />
Command="$(MSBuildThisFileDirectory)\..\tools\Etg.SimpleStubs.CodeGen.exe -ProjectPath:&quot;$(ProjectDir)$(ProjectName).csproj&quot; -OutputPath:&quot;$(SimpleStubsCodeGenOutput)&quot; -Configuration:&quot;$(Configuration)&quot; -Platform:&quot;$(Platform)&quot;" />
<ItemGroup>
<Compile Include="$(SimpleStubsCodeGenOutput)" />

Просмотреть файл

@ -25,9 +25,12 @@ namespace Etg.SimpleStubs.CodeGen
_config = config;
}
public async Task<string> GenerateStubs(string testProjectPath, string configuration)
public async Task<string> GenerateStubs(string testProjectPath, string configuration, string platform)
{
using (var workspace = MSBuildWorkspace.Create(new Dictionary<string, string> { { "Configuration", configuration } }))
using (var workspace = MSBuildWorkspace.Create(new Dictionary<string, string> {
{ "Configuration", configuration },
{ "Platform", platform}
}))
{
Project currentProject = await workspace.OpenProjectAsync(testProjectPath);
@ -38,7 +41,7 @@ namespace Etg.SimpleStubs.CodeGen
{
stringBuilder.AppendLine(diagnostic.ToString());
}
throw new Exception("Failed to open project, Errors: " + stringBuilder.ToString());
Console.WriteLine("Simplestubs encountered errors when opening the workspace; Stubs will be generated only for projects that successfully opened. Errors: " + stringBuilder.ToString());
}
if (currentProject == null)

Просмотреть файл

@ -39,6 +39,13 @@ namespace Etg.SimpleStubs.CodeGen
return;
}
string platform = parser.Arguments["-Platform"];
if (string.IsNullOrEmpty(platform))
{
Console.WriteLine(DecorateMessage($"Platform cannot be empty"));
return;
}
DiModule diModule = new DiModule(projectPath, outputPath);
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
@ -46,7 +53,7 @@ namespace Etg.SimpleStubs.CodeGen
try
{
string stubsCode = diModule.StubsGenerator.GenerateStubs(projectPath, configuration).Result;
string stubsCode = diModule.StubsGenerator.GenerateStubs(projectPath, configuration, platform).Result;
Console.WriteLine(DecorateMessage($"Writing stubs to file: {outputPath}"));
File.WriteAllText(outputPath, stubsCode);
}

Просмотреть файл

@ -15,7 +15,7 @@
<Exec
WorkingDirectory="$(ProjectDir)"
Command="..\..\src\SimpleStubs.CodeGen\bin\$(ConfigurationName)\Etg.SimpleStubs.CodeGen.exe -ProjectPath:&quot;$(ProjectDir)$(ProjectName).csproj'&quot; -OutputPath:&quot;$(SimpleStubsCodeGenOutput)&quot; -Configuration:&quot;$(Configuration)&quot;" />
Command="..\..\src\SimpleStubs.CodeGen\bin\$(ConfigurationName)\Etg.SimpleStubs.CodeGen.exe -ProjectPath:&quot;$(ProjectDir)$(ProjectName).csproj'&quot; -OutputPath:&quot;$(SimpleStubsCodeGenOutput)&quot; -Configuration:&quot;$(Configuration)&quot; -Platform:&quot;$(Platform)&quot;" />
<ItemGroup>
<Compile Include="$(SimpleStubsCodeGenOutput)" />