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:
Родитель
e145b124e5
Коммит
00f6b4c3f3
|
@ -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:"$(ProjectDir)$(ProjectName).csproj" -OutputPath:"$(SimpleStubsCodeGenOutput)" -Configuration:"$(Configuration)"" />
|
||||
Command="$(MSBuildThisFileDirectory)\..\tools\Etg.SimpleStubs.CodeGen.exe -ProjectPath:"$(ProjectDir)$(ProjectName).csproj" -OutputPath:"$(SimpleStubsCodeGenOutput)" -Configuration:"$(Configuration)" -Platform:"$(Platform)"" />
|
||||
|
||||
<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:"$(ProjectDir)$(ProjectName).csproj'" -OutputPath:"$(SimpleStubsCodeGenOutput)" -Configuration:"$(Configuration)"" />
|
||||
Command="..\..\src\SimpleStubs.CodeGen\bin\$(ConfigurationName)\Etg.SimpleStubs.CodeGen.exe -ProjectPath:"$(ProjectDir)$(ProjectName).csproj'" -OutputPath:"$(SimpleStubsCodeGenOutput)" -Configuration:"$(Configuration)" -Platform:"$(Platform)"" />
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="$(SimpleStubsCodeGenOutput)" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче