Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Add warning by default in SGEN (#24054)
Browse files Browse the repository at this point in the history
* Output warning by default if run the tool directly without /quiet parameter.

* add quiet parameter in the command.

* fix parameter error.

* Update the warning.
  • Loading branch information
huanwu authored Sep 17, 2017
1 parent 9c468a0 commit b5d9447
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Delete Condition="Exists('$(SerializerPdbImmediatePath)') == 'true'" Files="$(SerializerPdbImmediatePath)" />
<Delete Condition="Exists('$(SerializerCsImmediatePath)') == 'true'" Files="$(SerializerCsImmediatePath)" />
<Message Text="Running Serialization Tool" Importance="normal" />
<Exec Command="dotnet Microsoft.XmlSerializer.Generator $(IntermediateOutputPath)$(AssemblyName).dll /force" ContinueOnError="true"/>
<Exec Command="dotnet Microsoft.XmlSerializer.Generator $(IntermediateOutputPath)$(AssemblyName).dll /force /quiet" ContinueOnError="true"/>
<Warning Condition="Exists('$(SerializerCsImmediatePath)') != 'true'" Text="$(SGenWarningText)" />
<Csc Condition="Exists('$(SerializerCsImmediatePath)') == 'true'" ContinueOnError="true" OutputAssembly="$(SerializerDllImmediatePath)" References="@(ReferencePath);@(IntermediateAssembly)" EmitDebugInformation="$(DebugSymbols)" Sources="$(SerializerCsImmediatePath)" TargetType="Library" ToolExe="$(CscToolExe)" ToolPath="$(CscToolPath)"/>
<Warning Condition="Exists('$(SerializerDllImmediatePath)') != 'true' And Exists('$(SerializerCsImmediatePath)') == 'true'" Text="$(SGenWarningText)"/>
Expand Down
13 changes: 13 additions & 0 deletions src/Microsoft.XmlSerializer.Generator/src/Sgen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private int Run(string[] args)
var errs = new ArrayList();
bool force = false;
bool proxyOnly = false;
bool disableRun = true;

try
{
Expand Down Expand Up @@ -85,6 +86,10 @@ private int Run(string[] args)

assembly = value;
}
else if (ArgumentMatch(arg, "quiet"))
{
disableRun = false;
}
else
{
if (arg.EndsWith(".dll") || arg.EndsWith(".exe"))
Expand Down Expand Up @@ -122,6 +127,14 @@ private int Run(string[] args)
return 0;
}

if(disableRun)
{
Console.WriteLine("This tool is not intended to be used directly.");
Console.WriteLine("The feature is still under development.");
Console.WriteLine("Please refer to https://go.microsoft.com/fwlink/?linkid=858539 for more detail.");
return 0;
}

GenerateFile(types, assembly, proxyOnly, force, codePath);
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<SerializerName>$(AssemblyName).XmlSerializers</SerializerName>
</PropertyGroup>
<Message Text="Running Serialization Tool" Importance="normal" />
<Exec Command="$(GeneratorCliPath)dotnet $(OutputPath)dotnet-Microsoft.XmlSerializer.Generator.dll $(OutputPath)Microsoft.XmlSerializer.Generator.Tests.dll /force" />
<Exec Command="$(GeneratorCliPath)dotnet $(OutputPath)dotnet-Microsoft.XmlSerializer.Generator.dll $(OutputPath)Microsoft.XmlSerializer.Generator.Tests.dll /force /quiet" />
<Warning Condition="Exists('$(OutputPath)$(SerializerName).cs') != 'true'" Text="Fail to generate $(OutputPath)$(SerializerName).cs"/>
<Csc Condition="Exists('$(OutputPath)$(SerializerName).cs') == 'true' AND '$(MSBuildRuntimeType)' != 'core'"
OutputAssembly="$(OutputPath)$(SerializerName).dll"
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.XmlSerializer.Generator/tests/SGenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class SgenTests
public static void SgenCommandTest()
{
string codefile = "Microsoft.XmlSerializer.Generator.Tests.XmlSerializers.cs";
int n = Sgen.Main(new string[] { "Microsoft.XmlSerializer.Generator.Tests.dll", "/force"});
int n = Sgen.Main(new string[] { "Microsoft.XmlSerializer.Generator.Tests.dll", "/force", "/quiet"});
Assert.Equal(0, n);
Assert.True(File.Exists(codefile), string.Format("Fail to generate {0}.", codefile));
}
Expand Down

0 comments on commit b5d9447

Please sign in to comment.