Skip to content

Commit

Permalink
Implement an empty SGen .NET Core task (dotnet#5212)
Browse files Browse the repository at this point in the history
The SGen task has not been implemented on .NET Core and building a project with `<GenerateSerializationAssemblies>` is failing with what looks like an infrastructure error.

This PR is adding an empty implementation of the task which throws a nicer error pointing the user to the build-time serialization mechanism supported on .NET Core - Microsoft.XmlSerializer.Generator. The changes here are analogous to how the ResolveComReference task has been implemented to allow erroring out on Core.

Fixes dotnet#3583
  • Loading branch information
ladipro authored and sfoslund committed May 15, 2020
1 parent 16ebb1b commit 9e8c920
Show file tree
Hide file tree
Showing 20 changed files with 258 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,32 @@ public void CleanupTask(Microsoft.Build.Framework.ITask task) { }
public Microsoft.Build.Framework.TaskPropertyInfo[] GetTaskParameters() { throw null; }
public bool Initialize(string taskName, System.Collections.Generic.IDictionary<string, Microsoft.Build.Framework.TaskPropertyInfo> parameterGroup, string taskBody, Microsoft.Build.Framework.IBuildEngine taskFactoryLoggingHost) { throw null; }
}
public partial class SGen : Microsoft.Build.Tasks.ToolTaskExtension
{
public SGen() { }
[Microsoft.Build.Framework.RequiredAttribute]
public string BuildAssemblyName { get { throw null; } set { } }
[Microsoft.Build.Framework.RequiredAttribute]
public string BuildAssemblyPath { get { throw null; } set { } }
public bool DelaySign { get { throw null; } set { } }
public string KeyContainer { get { throw null; } set { } }
public string KeyFile { get { throw null; } set { } }
public string Platform { get { throw null; } set { } }
public string[] References { get { throw null; } set { } }
public string SdkToolsPath { get { throw null; } set { } }
[Microsoft.Build.Framework.OutputAttribute]
public Microsoft.Build.Framework.ITaskItem[] SerializationAssembly { get { throw null; } set { } }
public string SerializationAssemblyName { get { throw null; } }
[Microsoft.Build.Framework.RequiredAttribute]
public bool ShouldGenerateSerializer { get { throw null; } set { } }
protected override string ToolName { get { throw null; } }
public string[] Types { get { throw null; } set { } }
public bool UseKeep { get { throw null; } set { } }
[Microsoft.Build.Framework.RequiredAttribute]
public bool UseProxyTypes { get { throw null; } set { } }
public override bool Execute() { throw null; }
protected override string GenerateFullPathToTool() { throw null; }
}
public abstract partial class TaskExtension : Microsoft.Build.Utilities.Task
{
internal TaskExtension() { }
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@

<ItemGroup Condition="'$(MonoBuild)' == 'true'">
<Compile Remove="LC_Tests.cs" />
<Compile Remove="SGen_Tests.cs" />
</ItemGroup>

<ItemGroup Condition="$(TargetFrameworkIdentifier) != '.NETFramework'">
Expand Down Expand Up @@ -126,7 +127,6 @@
<Compile Remove="ResolveComReference_Tests.cs" />
<Compile Remove="ResolveSDKReference_Tests.cs" />
<Compile Remove="SdkToolsPathUtility_Tests.cs" />
<Compile Remove="SGen_Tests.cs" />
<Compile Remove="TlbImp_Tests.cs" />
<Compile Remove="VisualBasicParserUtilitites_Tests.cs" />
<Compile Remove="VisualBasicTokenizer_Tests.cs" />
Expand Down
36 changes: 36 additions & 0 deletions src/Tasks.UnitTests/SGen_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,46 @@
using Microsoft.Build.Utilities;
using Microsoft.Build.Shared;
using System.IO;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
using Shouldly;

namespace Microsoft.Build.UnitTests
{
public class SGen_Tests
{
#if RUNTIME_TYPE_NETCORE
[Fact]
public void TaskFailsOnCore()
{
using (TestEnvironment testenv = TestEnvironment.Create())
{
MockLogger logger = ObjectModelHelpers.BuildProjectExpectFailure(@$"
<Project>
<Target Name=""MyTarget"">
<SGen
BuildAssemblyName=""Foo""
BuildAssemblyPath=""Foo""
ShouldGenerateSerializer=""true""
UseProxyTypes=""true""
UseKeep=""true""
References=""Foo""
KeyContainer=""Foo""
KeyFile=""Foo""
DelaySign=""true""
SerializationAssembly=""Foo""
SdkToolsPath=""Foo""
Platform=""Foo""
Types=""Foo""
/>
</Target>
</Project>");
logger.ErrorCount.ShouldBe(1);
logger.Errors.First().Code.ShouldBe("MSB3474");
}
}
#else
internal class SGenExtension : SGen
{
internal string CommandLine()
Expand Down Expand Up @@ -56,6 +90,7 @@ public void TestKeepFlagTrue()

Assert.True(commandLine.IndexOf("/keep", StringComparison.OrdinalIgnoreCase) >= 0);
}

[Fact]
public void TestKeepFlagFalse()
{
Expand Down Expand Up @@ -242,5 +277,6 @@ public void TestReferencesCommandLine()

Assert.Equal(targetCommandLine, commandLine);
}
#endif
}
}
6 changes: 3 additions & 3 deletions src/Tasks/Microsoft.Build.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@
<Compile Include="RoslynCodeTaskFactory\RoslynCodeTaskFactoryCodeType.cs" />
<Compile Include="RoslynCodeTaskFactory\RoslynCodeTaskFactoryCompilers.cs" />
<Compile Include="RoslynCodeTaskFactory\RoslynCodeTaskFactoryTaskInfo.cs" />
<Compile Include="SGen.cs" Condition="'$(MonoBuild)' != 'true'">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="System.Design.cs" />
<Compile Include="system.design\stronglytypedresourcebuilder.cs" />
<Compile Include="TaskExtension.cs">
Expand Down Expand Up @@ -627,9 +630,6 @@
<Compile Include="RequiresFramework35SP1Assembly.cs" Condition="'$(MonoBuild)' != 'true'">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="SGen.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="SignFile.cs" Condition="'$(MonoBuild)' != 'true'">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down
4 changes: 4 additions & 0 deletions src/Tasks/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +1967,10 @@
<value>MSB3473: Path for "{0}" is invalid. {1}</value>
<comment>{StrBegin="MSB3473: "}</comment>
</data>
<data name="SGen.TaskNotSupported">
<value>MSB3474: The task "{0}" is not supported on the .NET Core version of MSBuild. Use the Microsoft XML Serializer Generator package instead. See https://go.microsoft.com/fwlink/?linkid=858594 for more information.</value>
<comment>{StrBegin="MSB3474: "}</comment>
</data>
<!--
The SignFile message bucket is: MSB3481 - MSB3490
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Resources/xlf/Strings.en.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Resources/xlf/Strings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Resources/xlf/Strings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Resources/xlf/Strings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Resources/xlf/Strings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Resources/xlf/Strings.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Resources/xlf/Strings.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Tasks/Resources/xlf/Strings.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9e8c920

Please sign in to comment.