diff --git a/MessagePack.sln b/MessagePack.sln index b530efe4..bb51fbda 100644 --- a/MessagePack.sln +++ b/MessagePack.sln @@ -79,6 +79,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePack.GeneratorCore", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePack.Generator", "src\MessagePack.Generator\MessagePack.Generator.csproj", "{32C91908-5CAD-4C95-B240-ACBBACAC9476}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePack.MSBuild.Tasks", "src\MessagePack.MSBuild.Tasks\MessagePack.MSBuild.Tasks.csproj", "{8DB135F5-A6FE-44E4-9853-7B48ED21F21B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -173,6 +175,10 @@ Global {32C91908-5CAD-4C95-B240-ACBBACAC9476}.Debug|Any CPU.Build.0 = Debug|Any CPU {32C91908-5CAD-4C95-B240-ACBBACAC9476}.Release|Any CPU.ActiveCfg = Release|Any CPU {32C91908-5CAD-4C95-B240-ACBBACAC9476}.Release|Any CPU.Build.0 = Release|Any CPU + {8DB135F5-A6FE-44E4-9853-7B48ED21F21B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8DB135F5-A6FE-44E4-9853-7B48ED21F21B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8DB135F5-A6FE-44E4-9853-7B48ED21F21B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8DB135F5-A6FE-44E4-9853-7B48ED21F21B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -200,6 +206,7 @@ Global {8D9FD130-7905-47D8-A25C-7FDEE28EA0E8} = {19FE674A-AC94-4E7E-B24C-2285D1D04CDE} {9962132D-A271-4E68-ACC1-18FA93462552} = {86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC} {32C91908-5CAD-4C95-B240-ACBBACAC9476} = {86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC} + {8DB135F5-A6FE-44E4-9853-7B48ED21F21B} = {86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B3911209-2DBF-47F8-98F6-BBC0EDFE63DE} diff --git a/src/MessagePack.Generator/MessagePack.Generator.csproj b/src/MessagePack.Generator/MessagePack.Generator.csproj index 3f2ceff9..75314715 100644 --- a/src/MessagePack.Generator/MessagePack.Generator.csproj +++ b/src/MessagePack.Generator/MessagePack.Generator.csproj @@ -3,6 +3,15 @@ Exe netcoreapp2.2 + latest + true + dotnet-mpc + + + MessagePack Code Generator + MessagePack standalone code generator. + MsgPack;MessagePack;Serialization;Formatter;Serializer;Unity;Xamarin + MessagePack.Generator @@ -13,4 +22,4 @@ - + \ No newline at end of file diff --git a/src/MessagePack.MSBuild.Tasks/MessagePack.MSBuild.Tasks.csproj b/src/MessagePack.MSBuild.Tasks/MessagePack.MSBuild.Tasks.csproj new file mode 100644 index 00000000..e442a5ed --- /dev/null +++ b/src/MessagePack.MSBuild.Tasks/MessagePack.MSBuild.Tasks.csproj @@ -0,0 +1,49 @@ + + + + netstandard2.0 + latest + + + true + tasks + + true + + true + MessagePack CodeGenerator Tasks + MSBuild Tasks of MessagePack for C#. + MsgPack;MessagePack;Serialization;Formatter;Serializer;Unity;Xamarin + MessagePack.MSBuild.Tasks + + + + + + + + + + + + + + + + + + + + + <_PackageFiles Include="$(OutDir)\**\*.dll" Exclude="$(OutDir)$(TargetFileName)"> + tasks\netstandard2.0\%(RecursiveDir) + false + Content + + + + + diff --git a/src/MessagePack.MSBuild.Tasks/MessagePackGenerator.cs b/src/MessagePack.MSBuild.Tasks/MessagePackGenerator.cs new file mode 100644 index 00000000..3de17611 --- /dev/null +++ b/src/MessagePack.MSBuild.Tasks/MessagePackGenerator.cs @@ -0,0 +1,49 @@ +using System; +using System.Threading; +using MessagePackCompiler; +using Microsoft.Build.Framework; + +namespace MessagePack.MSBuild.Tasks +{ + public class MessagePackGenerator : Microsoft.Build.Utilities.Task + { + [Required] + public string Input { get; set; } + [Required] + public string Output { get; set; } + + public string ConditionalSymbol { get; set; } + + public string ResolverName { get; set; } + + public string Namespace { get; set; } + + public bool UseMapMode { get; set; } + + public string MultipleIfDirectiveOutputSymbols { get; set; } + + public override bool Execute() + { + try + { + new CodeGenerator(x => this.Log.LogMessage(x), CancellationToken.None) + .GenerateFileAsync( + Input, + Output, + ConditionalSymbol, + ResolverName ?? "GeneratedResolver", + Namespace ?? "MessagePack", + UseMapMode, + MultipleIfDirectiveOutputSymbols + ) + .GetAwaiter().GetResult(); + } + catch (Exception ex) + { + this.Log.LogErrorFromException(ex, true); + return false; + } + return true; + } + } +} diff --git a/src/MessagePack.MSBuild.Tasks/build/MessagePack.MSBUild.Tasks.props b/src/MessagePack.MSBuild.Tasks/build/MessagePack.MSBUild.Tasks.props new file mode 100644 index 00000000..61ad19d0 --- /dev/null +++ b/src/MessagePack.MSBuild.Tasks/build/MessagePack.MSBUild.Tasks.props @@ -0,0 +1,9 @@ + + + + netstandard2.0 + $(MSBuildThisFileDirectory)..\tasks\$(TaskFolder)\MessagePack.MSBuild.Tasks.dll + + + + \ No newline at end of file