You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by GitBox <gi...@apache.org> on 2022/11/14 17:26:14 UTC

[GitHub] [avro] zcsizmadia opened a new pull request, #1966: AVRO-3673: Add MSBuild AvroGenTask

zcsizmadia opened a new pull request, #1966:
URL: https://github.com/apache/avro/pull/1966

   ## What is the purpose of the change
   
   *Adding a nuget package for AvroGenTask MSBuild task, AVRO-3673.*
   
   ## Verifying this change
   
   This change added tests and can be verified by running the C# based unit tests.
   
   ## Documentation
   
   - Does this pull request introduce a new feature? (yes)
   - If yes, how is the feature documented? (README.MD example)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1021878869


##########
lang/csharp/src/apache/msbuild/AvroGenTask.cs:
##########
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Avro.msbuild
+{
+    public class AvroGenTask : Task
+    {
+        public override bool Execute()
+        {
+            try
+            {
+                Dictionary<string, string> namespaceMapping = new Dictionary<string, string>();
+
+                MessageImportance messageImportance = string.IsNullOrEmpty(MessageLevel) ? 
+                    MessageImportance.Normal :
+                    (MessageImportance)Enum.Parse(typeof(MessageImportance), MessageLevel);
+
+                var codegen = new CodeGen();
+
+                if (!string.IsNullOrEmpty(NamespaceMapping))
+                {
+                    foreach(var mapping in NamespaceMapping.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
+                    {
+                        var parts = mapping.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
+                        if (parts.Length != 2)
+                        {
+                            throw new ArgumentException("Malformed namespace mapping. Required format is \"avro.namespace:csharp.namespace\"");
+                        }
+                        namespaceMapping[parts[0]] = parts[1];
+                    }
+                }
+
+                if (SchemaFiles != null)
+                {
+                    foreach (var schemaFile in SchemaFiles)
+                    {
+                        var schemaText = System.IO.File.ReadAllText(schemaFile.ItemSpec);
+                        codegen.AddSchema(schemaText, namespaceMapping);
+                    }
+                }
+                if (ProtocolFiles != null)
+                {
+                    foreach (var protocolFile in ProtocolFiles)
+                    {
+                        var protocolText = System.IO.File.ReadAllText(protocolFile.ItemSpec);
+                        codegen.AddProtocol(protocolText, namespaceMapping);
+                    }
+                }
+
+                var generateCode = codegen.GenerateCode();
+                var namespaces = generateCode.Namespaces;
+                for (var i = namespaces.Count - 1; i >= 0; i--)
+                {
+                    var types = namespaces[i].Types;
+                    for (var j = types.Count - 1; j >= 0; j--)
+                    {
+                        Log.LogMessage(messageImportance, "Generating {0}.{1}", namespaces[i].Name, types[j].Name);
+                    }
+                }
+
+                codegen.WriteTypes(OutDir.ItemSpec, SkipDirectories);
+            }
+            catch(Exception ex)
+            {
+                Log.LogErrorFromException(ex);
+            }

Review Comment:
   Catching generic exception is the intent here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "zcsizmadia (via GitHub)" <gi...@apache.org>.
zcsizmadia commented on PR #1966:
URL: https://github.com/apache/avro/pull/1966#issuecomment-1436032071

   The main Avro library depends on System.CodeDom. So yes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] KalleOlaviNiemitalo commented on pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "KalleOlaviNiemitalo (via GitHub)" <gi...@apache.org>.
KalleOlaviNiemitalo commented on PR #1966:
URL: https://github.com/apache/avro/pull/1966#issuecomment-1436046044

   "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software." I would think this applies to those packages that actually include a copy of the software rather than require the user to download it from elsewhere.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] github-code-scanning[bot] commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
github-code-scanning[bot] commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1021870151


##########
lang/csharp/src/apache/msbuild/AvroGenTask.cs:
##########
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Avro.msbuild
+{
+    public class AvroGenTask : Task
+    {
+        public override bool Execute()
+        {
+            try
+            {
+                Dictionary<string, string> namespaceMapping = new Dictionary<string, string>();
+
+                MessageImportance messageImportance = string.IsNullOrEmpty(MessageLevel) ? 
+                    MessageImportance.Normal :
+                    (MessageImportance)Enum.Parse(typeof(MessageImportance), MessageLevel);
+
+                var codegen = new CodeGen();
+
+                if (!string.IsNullOrEmpty(NamespaceMapping))
+                {
+                    foreach(var mapping in NamespaceMapping.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
+                    {
+                        var parts = mapping.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
+                        if (parts.Length != 2)
+                        {
+                            throw new ArgumentException("Malformed namespace mapping. Required format is \"avro.namespace:csharp.namespace\"");
+                        }
+                        namespaceMapping[parts[0]] = parts[1];
+                    }
+                }
+
+                if (SchemaFiles != null)
+                {
+                    foreach (var schemaFile in SchemaFiles)
+                    {
+                        var schemaText = System.IO.File.ReadAllText(schemaFile.ItemSpec);
+                        codegen.AddSchema(schemaText, namespaceMapping);
+                    }
+                }
+                if (ProtocolFiles != null)
+                {
+                    foreach (var protocolFile in ProtocolFiles)
+                    {
+                        var protocolText = System.IO.File.ReadAllText(protocolFile.ItemSpec);
+                        codegen.AddProtocol(protocolText, namespaceMapping);
+                    }
+                }
+
+                var generateCode = codegen.GenerateCode();
+                var namespaces = generateCode.Namespaces;
+                for (var i = namespaces.Count - 1; i >= 0; i--)
+                {
+                    var types = namespaces[i].Types;
+                    for (var j = types.Count - 1; j >= 0; j--)
+                    {
+                        Log.LogMessage(messageImportance, "Generating {0}.{1}", namespaces[i].Name, types[j].Name);
+                    }
+                }
+
+                codegen.WriteTypes(OutDir.ItemSpec, SkipDirectories);
+            }
+            catch(Exception ex)
+            {
+                Log.LogErrorFromException(ex);
+            }

Review Comment:
   ## Generic catch clause
   
   Generic catch clause.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/2947)



##########
lang/csharp/src/apache/msbuild/AvroGenTask.cs:
##########
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Avro.msbuild
+{
+    public class AvroGenTask : Task
+    {
+        public override bool Execute()
+        {
+            try
+            {
+                Dictionary<string, string> namespaceMapping = new Dictionary<string, string>();
+
+                MessageImportance messageImportance = string.IsNullOrEmpty(MessageLevel) ? 
+                    MessageImportance.Normal :
+                    (MessageImportance)Enum.Parse(typeof(MessageImportance), MessageLevel);
+
+                var codegen = new CodeGen();
+
+                if (!string.IsNullOrEmpty(NamespaceMapping))
+                {
+                    foreach(var mapping in NamespaceMapping.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
+                    {
+                        var parts = mapping.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
+                        if (parts.Length != 2)
+                        {
+                            throw new ArgumentException("Malformed namespace mapping. Required format is \"avro.namespace:csharp.namespace\"");
+                        }
+                        namespaceMapping[parts[0]] = parts[1];
+                    }
+                }
+
+                if (SchemaFiles != null)
+                {
+                    foreach (var schemaFile in SchemaFiles)
+                    {
+                        var schemaText = System.IO.File.ReadAllText(schemaFile.ItemSpec);
+                        codegen.AddSchema(schemaText, namespaceMapping);
+                    }

Review Comment:
   ## Missed opportunity to use Select
   
   This foreach loop immediately [maps its iteration variable to another variable](1) - consider mapping the sequence explicitly using '.Select(...)'.
   
   [Show more details](https://github.com/apache/avro/security/code-scanning/2948)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "zcsizmadia (via GitHub)" <gi...@apache.org>.
zcsizmadia commented on PR #1966:
URL: https://github.com/apache/avro/pull/1966#issuecomment-1436033098

   I am not a License expert, however System.CodeDom is part of the C# NET Core runtime libraries and they live in https://github.com/dotnet/runtime. If System.COdeDom is included in the LICENSE file, than all the other C# runtime libraries should be there as well. The indirect dependencies for the Avro class library is pretty wide if we widen it into the .NET runtime libraries.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] KalleOlaviNiemitalo commented on pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "KalleOlaviNiemitalo (via GitHub)" <gi...@apache.org>.
KalleOlaviNiemitalo commented on PR #1966:
URL: https://github.com/apache/avro/pull/1966#issuecomment-1477356308

   I've filed [[AVRO-3614] Remove System.CodeDom dependency from main library](https://issues.apache.org/jira/browse/AVRO-3614), but CodeDom would still be needed in AvroGen unless the code generation were rewritten using hardcoded knowledge about C# syntax -- which wouldn't hurt too much as the code generation currently supports only C# anyway.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1021875077


##########
lang/csharp/src/apache/msbuild/AvroGenTask.cs:
##########
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Avro.msbuild
+{
+    public class AvroGenTask : Task
+    {
+        public override bool Execute()
+        {
+            try
+            {
+                Dictionary<string, string> namespaceMapping = new Dictionary<string, string>();
+
+                MessageImportance messageImportance = string.IsNullOrEmpty(MessageLevel) ? 
+                    MessageImportance.Normal :
+                    (MessageImportance)Enum.Parse(typeof(MessageImportance), MessageLevel);
+
+                var codegen = new CodeGen();
+
+                if (!string.IsNullOrEmpty(NamespaceMapping))
+                {
+                    foreach(var mapping in NamespaceMapping.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
+                    {
+                        var parts = mapping.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
+                        if (parts.Length != 2)
+                        {
+                            throw new ArgumentException("Malformed namespace mapping. Required format is \"avro.namespace:csharp.namespace\"");
+                        }
+                        namespaceMapping[parts[0]] = parts[1];
+                    }
+                }
+
+                if (SchemaFiles != null)
+                {
+                    foreach (var schemaFile in SchemaFiles)
+                    {
+                        var schemaText = System.IO.File.ReadAllText(schemaFile.ItemSpec);
+                        codegen.AddSchema(schemaText, namespaceMapping);
+                    }

Review Comment:
   IMO using Select here would make the code less readable.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] KalleOlaviNiemitalo commented on pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "KalleOlaviNiemitalo (via GitHub)" <gi...@apache.org>.
KalleOlaviNiemitalo commented on PR #1966:
URL: https://github.com/apache/avro/pull/1966#issuecomment-1435901221

   What are the dependencies that end up being copied into the NuGet package; do any of them have license terms that require additional legal notices in the package?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on PR #1966:
URL: https://github.com/apache/avro/pull/1966#issuecomment-1314514028

   Additionally this MSBuild task lets to compile multiple schema files at the same time and resolving dependencies between dependent schema files. E.g. some sub types are specified ina  seperate schema file. The avrogen tool currently is not capable to do that, only one schema file can be compiled at one time


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1022048214


##########
lang/csharp/src/apache/msbuild/Apache.Avro.MSBuild.props:
##########
@@ -0,0 +1,24 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       https://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<Project TreatAsLocalProperty="TaskTargetFramework;TaskAssembly">

Review Comment:
   I dont think it is an issue or a concern at all, however simplified the recommended code pattern, since there is only one target framework.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] alexrosenfeld10 commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1172691445


##########
lang/csharp/src/apache/msbuild/AvroGenTask.cs:
##########
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.IO;
+using System.Linq;
+using System.Collections.Generic;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Avro.msbuild
+{
+    public class AvroGenTask : Task
+    {
+        public override bool Execute()
+        {
+            try
+            {
+                Dictionary<string, string> namespaceMapping = new Dictionary<string, string>();
+
+                MessageImportance messageImportance = string.IsNullOrEmpty(MessageLevel) ? 
+                    MessageImportance.Normal :
+                    (MessageImportance)Enum.Parse(typeof(MessageImportance), MessageLevel);
+
+                var codegen = new CodeGen();
+
+                if (!string.IsNullOrEmpty(NamespaceMapping))
+                {
+                    foreach(var mapping in NamespaceMapping.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
+                    {
+                        var parts = mapping.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
+                        if (parts.Length != 2)
+                        {
+                            throw new ArgumentException("Malformed namespace mapping. Required format is \"avro.namespace:csharp.namespace\"");
+                        }
+                        namespaceMapping[parts[0]] = parts[1];
+                    }
+                }
+
+                if (SchemaFiles != null)
+                {
+                    foreach (var schemaFile in SchemaFiles)
+                    {
+                        var schemaText = System.IO.File.ReadAllText(schemaFile.ItemSpec);
+                        codegen.AddSchema(schemaText, namespaceMapping);

Review Comment:
   @zcsizmadia I'm building something similar myself right now using C# Source Generators. I'm having an issue where references to common shared schemas don't resolve properly, and my code is pretty much the same as yours here. Does your code work in this case? Details below:
   
   
   Top level schema I want to generate C# for:
   ```yaml
   {
       "name": "MyModel",
       "namespace": "My.Model",
       "type": "record",
       "fields": [
           {
               "name": "Planet",
               "type": "My.Model.PlanetEnum",
           }
       ]
   }
   ```
   
   The `RepositoryEnum` definition, shared between multiple schemas:
   
   ```yaml
   {
     "name": "PlanetEnum",
     "namespace": "My.Model",
     "type": "enum",
     "symbols": [
       "Earth",
       "Mars"
     ]
   }
   ```
   
   
   Here's the code I'm using to generate the C#:
   
   ```csharp
           var codeCompileUnit = new CodeGen
           {
               Schemas =
               {
                   Schema.Parse(schemaText)
               },
           }.GenerateCode();
   
           var stringWriter = new StringWriter(new StringBuilder());
           var provider = CodeDomProvider.CreateProvider("csharp");
           provider.GenerateCodeFromCompileUnit(codeCompileUnit, stringWriter, new CodeGeneratorOptions());
           var schemaCode = stringWriter.ToString();
           return schemaCode;
   ```
   
   
   This fails because it can't make the connection between the two separated schema definition files. If I add multiple calls to `Schema.Parse`, it still fails. Any thoughts? Would a fix for this be worked into your PR here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] KalleOlaviNiemitalo commented on pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "KalleOlaviNiemitalo (via GitHub)" <gi...@apache.org>.
KalleOlaviNiemitalo commented on PR #1966:
URL: https://github.com/apache/avro/pull/1966#issuecomment-1436030749

   Is System.CodeDom included? I don't see anything about that in <https://github.com/apache/avro/blob/0f4cdc0cb986452c158f8d8a651ea92512ff8282/lang/csharp/LICENSE> or <https://github.com/apache/avro/blob/0f4cdc0cb986452c158f8d8a651ea92512ff8282/lang/csharp/NOTICE>.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1022130850


##########
lang/csharp/README.md:
##########
@@ -39,6 +39,36 @@ Install-Package Apache.Avro
 2. By updating the versions in our libraries, we require users of the library to update to a version equal to or greater than the version we reference. For example, if a user were to reference an older version of Newtonsoft.Json, they would be forced to update to a newer version before they could use a new version of the Avro library.
 In short, we should only update the version of the dependencies in our libraries if we absolutely must for functionality that we require. We leave it up to the users of the library as to whether or not they want the latest and greatest of a particularly dependency. We're only going to require the bare minimum.
 
+## MSBuild Avro Generator Task
+
+MSBuild task `AvroGenTask` can be used to compile avro schema or protocol files from `.csproj`, without explicitly calling `avrogen` tool binary.
+
+Example:
+
+```
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net6.0</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <SchemaFiles Include="schemas/**/*.avsc" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Apache.Avro" Version="1.11.2 />
+    <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
+  </ItemGroup>
+
+  <Target Name="AvroGenerate" BeforeTargets="CoreCompile">
+    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" />

Review Comment:
   This is the same way avrogen would work. The cs generation will happen every time  this task is triggered. To implement dependencies, basic mechanism can be implemented, using Inputs and Outputs props of Target.
   
   SInce the schema -> sc mapping is not 1 to 1, implementing the dependencies inside the codegen library is not trivial (as it is currently implemented). This PR simply let the user use an MSBuild task tinstead of calling avrogen. Avrogen as a tool has a limitation that it relies on a specific SDK version. E.g until the net7 version of avrogen is not released, avrogen cannot be used in a net7 only NET SDK container.
   
   Using MSBuild tasks are solving that issue, since the MSBuild task package is targeting netstandard2.0.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on PR #1966:
URL: https://github.com/apache/avro/pull/1966#issuecomment-1314121160

   Example `.csproj` from README.MD:
   
   ```
   <Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
       <OutputType>Exe</OutputType>
       <TargetFramework>net6.0</TargetFramework>
     </PropertyGroup>
     <ItemGroup>
       <SchemaFiles Include="schemas/**/*.avsc" />
     </ItemGroup>
     <ItemGroup>
       <PackageReference Include="Apache.Avro" Version="1.11.2 />
       <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
     </ItemGroup>
     <Target Name="AvroGenerate" BeforeTargets="CoreCompile">
       <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" />
     </Target>
   </Project>
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] KalleOlaviNiemitalo commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
KalleOlaviNiemitalo commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1022036242


##########
lang/csharp/src/apache/msbuild/Apache.Avro.MSBuild.props:
##########
@@ -0,0 +1,24 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       https://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<Project TreatAsLocalProperty="TaskTargetFramework;TaskAssembly">

Review Comment:
   TreatAsLocalProperty prevents these from being overridden from the command line, but AFAIK they can still conflict with properties defined in other imported project files, so you should use more unique names or just no properties at all.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] alexrosenfeld10 commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1172691445


##########
lang/csharp/src/apache/msbuild/AvroGenTask.cs:
##########
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.IO;
+using System.Linq;
+using System.Collections.Generic;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Avro.msbuild
+{
+    public class AvroGenTask : Task
+    {
+        public override bool Execute()
+        {
+            try
+            {
+                Dictionary<string, string> namespaceMapping = new Dictionary<string, string>();
+
+                MessageImportance messageImportance = string.IsNullOrEmpty(MessageLevel) ? 
+                    MessageImportance.Normal :
+                    (MessageImportance)Enum.Parse(typeof(MessageImportance), MessageLevel);
+
+                var codegen = new CodeGen();
+
+                if (!string.IsNullOrEmpty(NamespaceMapping))
+                {
+                    foreach(var mapping in NamespaceMapping.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
+                    {
+                        var parts = mapping.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
+                        if (parts.Length != 2)
+                        {
+                            throw new ArgumentException("Malformed namespace mapping. Required format is \"avro.namespace:csharp.namespace\"");
+                        }
+                        namespaceMapping[parts[0]] = parts[1];
+                    }
+                }
+
+                if (SchemaFiles != null)
+                {
+                    foreach (var schemaFile in SchemaFiles)
+                    {
+                        var schemaText = System.IO.File.ReadAllText(schemaFile.ItemSpec);
+                        codegen.AddSchema(schemaText, namespaceMapping);

Review Comment:
   @zcsizmadia I'm building something similar myself right now using C# Source Generators. I'm having an issue where references to common shared schemas don't resolve properly, and my code is pretty much the same as yours here. Does your code work in this case? Details below:
   
   
   Top level schema I want to generate C# for:
   ```yaml
   {
       "name": "MyModel",
       "namespace": "My.Model",
       "type": "record",
       "fields": [
           {
               "name": "Planet",
               "type": "My.Model.PlanetEnum",
           }
       ]
   }
   ```
   
   The `PlanetEnum` definition, shared between multiple schemas:
   
   ```yaml
   {
     "name": "PlanetEnum",
     "namespace": "My.Model",
     "type": "enum",
     "symbols": [
       "Earth",
       "Mars"
     ]
   }
   ```
   
   
   Here's the code I'm using to generate the C#:
   
   ```csharp
           var codeCompileUnit = new CodeGen
           {
               Schemas =
               {
                   Schema.Parse(schemaText)
               },
           }.GenerateCode();
   
           var stringWriter = new StringWriter(new StringBuilder());
           var provider = CodeDomProvider.CreateProvider("csharp");
           provider.GenerateCodeFromCompileUnit(codeCompileUnit, stringWriter, new CodeGeneratorOptions());
           var schemaCode = stringWriter.ToString();
           return schemaCode;
   ```
   
   
   This fails because it can't make the connection between the two separated schema definition files. If I add multiple calls to `Schema.Parse`, it still fails. Any thoughts? Would a fix for this be worked into your PR here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] alexrosenfeld10 commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1172695000


##########
lang/csharp/src/apache/msbuild/AvroGenTask.cs:
##########
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.IO;
+using System.Linq;
+using System.Collections.Generic;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Avro.msbuild
+{
+    public class AvroGenTask : Task
+    {
+        public override bool Execute()
+        {
+            try
+            {
+                Dictionary<string, string> namespaceMapping = new Dictionary<string, string>();
+
+                MessageImportance messageImportance = string.IsNullOrEmpty(MessageLevel) ? 
+                    MessageImportance.Normal :
+                    (MessageImportance)Enum.Parse(typeof(MessageImportance), MessageLevel);
+
+                var codegen = new CodeGen();
+
+                if (!string.IsNullOrEmpty(NamespaceMapping))
+                {
+                    foreach(var mapping in NamespaceMapping.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
+                    {
+                        var parts = mapping.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
+                        if (parts.Length != 2)
+                        {
+                            throw new ArgumentException("Malformed namespace mapping. Required format is \"avro.namespace:csharp.namespace\"");
+                        }
+                        namespaceMapping[parts[0]] = parts[1];
+                    }
+                }
+
+                if (SchemaFiles != null)
+                {
+                    foreach (var schemaFile in SchemaFiles)
+                    {
+                        var schemaText = System.IO.File.ReadAllText(schemaFile.ItemSpec);
+                        codegen.AddSchema(schemaText, namespaceMapping);

Review Comment:
   Even if I inline the shared enum definition, like so:
   
   ```csharp
           var codeCompileUnit = new CodeGen
           {
               Schemas =
               {
                   Schema.Parse("""
   {
     "name": "PlanetEnum",
     "namespace": "My.Model",
     "type": "enum",
     "symbols": [
       "Earth",
       "Mars"
     ]
   }
   """),
                   Schema.Parse(schemaText)
               },
           }.GenerateCode();
   ```
   
   it fails with:
   ```text
   Avro.SchemaParseException: Undefined name: My.Model.PlanetEnum at 'fields[4].type'
      at Avro.Schema.ParseJson(JToken jtok, SchemaNames names, String encspace)
      at Avro.RecordSchema.createField(JToken jfield, Int32 pos, SchemaNames names, String encspace)
      at Avro.RecordSchema.NewInstance(Type type, JToken jtok, PropertyMap props, SchemaNames names, String encspace)
      at Avro.NamedSchema.NewInstance(JObject jo, PropertyMap props, SchemaNames names, String encspace)
      at Avro.Schema.ParseJson(JToken jtok, SchemaNames names, String encspace)
      at Avro.Schema.Parse(String json, SchemaNames names, String encspace)
      at Avro.Schema.Parse(String json)
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1022135052


##########
lang/csharp/README.md:
##########
@@ -39,6 +39,36 @@ Install-Package Apache.Avro
 2. By updating the versions in our libraries, we require users of the library to update to a version equal to or greater than the version we reference. For example, if a user were to reference an older version of Newtonsoft.Json, they would be forced to update to a newer version before they could use a new version of the Avro library.
 In short, we should only update the version of the dependencies in our libraries if we absolutely must for functionality that we require. We leave it up to the users of the library as to whether or not they want the latest and greatest of a particularly dependency. We're only going to require the bare minimum.
 
+## MSBuild Avro Generator Task
+
+MSBuild task `AvroGenTask` can be used to compile avro schema or protocol files from `.csproj`, without explicitly calling `avrogen` tool binary.
+
+Example:
+
+```
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net6.0</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <SchemaFiles Include="schemas/**/*.avsc" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Apache.Avro" Version="1.11.2 />
+    <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
+  </ItemGroup>
+
+  <Target Name="AvroGenerate" BeforeTargets="CoreCompile">
+    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" />

Review Comment:
   Here is an example how  dependencies can be solved via Target:
   
   ```
   <Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
       <OutputType>Exe</OutputType>
       <TargetFramework>net6.0</TargetFramework>
     </PropertyGroup>
   
     <ItemGroup>
       <SchemaFiles Include="schemas/**/*.avsc" />
     </ItemGroup>
   
     <ItemGroup>
       <PackageReference Include="Apache.Avro" Version="1.11.2 />
       <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
     </ItemGroup>
   
     <Target Name="AvroGenerate" BeforeTargets="CoreCompile" Inputs="@(SchemaFiles)" Outputs="generated/.AvroGenSuccess" >
       <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" /> <!-- Avro code geneartion -->
       <WriteLinesToFile File="generated/.AvroGenSuccess" Overwrite="true" Lines="%(SchemaFiles.Identity)" />
     </Target>
   
     <Target Name="AvroGenClean" BeforeTargets="BeforeClean">
       <RemoveDir Directories="generated" />
     </Target>
   </Project>
   ```
   
   The first time avrogen runs, at completion a success marker file is created. Next time MSBuild will compare the timestamp of all input schema files and the success file, if any of the input schemas were changed since the last success, the files are re-avrogen'd. If not, no avrogen is will be triggered.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1022135052


##########
lang/csharp/README.md:
##########
@@ -39,6 +39,36 @@ Install-Package Apache.Avro
 2. By updating the versions in our libraries, we require users of the library to update to a version equal to or greater than the version we reference. For example, if a user were to reference an older version of Newtonsoft.Json, they would be forced to update to a newer version before they could use a new version of the Avro library.
 In short, we should only update the version of the dependencies in our libraries if we absolutely must for functionality that we require. We leave it up to the users of the library as to whether or not they want the latest and greatest of a particularly dependency. We're only going to require the bare minimum.
 
+## MSBuild Avro Generator Task
+
+MSBuild task `AvroGenTask` can be used to compile avro schema or protocol files from `.csproj`, without explicitly calling `avrogen` tool binary.
+
+Example:
+
+```
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net6.0</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <SchemaFiles Include="schemas/**/*.avsc" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Apache.Avro" Version="1.11.2 />
+    <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
+  </ItemGroup>
+
+  <Target Name="AvroGenerate" BeforeTargets="CoreCompile">
+    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" />

Review Comment:
   Here is an example how  dependencies can be solved via Target:
   
   ```
   <Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
       <OutputType>Exe</OutputType>
       <TargetFramework>net6.0</TargetFramework>
     </PropertyGroup>
     <ItemGroup>
       <SchemaFiles Include="schemas/**/*.avsc" />
     </ItemGroup>
     <ItemGroup>
       <PackageReference Include="Apache.Avro" Version="1.11.2 />
       <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
     </ItemGroup>
     <Target Name="AvroGenerate" BeforeTargets="CoreCompile" Inputs="@(SchemaFiles)" Outputs="generated/.AvroGenSuccess" >
       <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" /> <!-- Avro code geneartion -->
       <WriteLinesToFile File="generated/.AvroGenSuccess" Overwrite="true" Lines="%(SchemaFiles.Identity)" />
     </Target>
   
     <Target Name="AvroGenClean" BeforeTargets="BeforeClean">
       <RemoveDir Directories="generated" />
     </Target>
   </Project>
   ```
   
   The first time avrogen runs, at completion a success marker file is created. Next time MSBuild will compare the timestamp of all input schema files and the success file, if any of the input schemas were changed since the last success, the files are re-avrogen'd. If not, no avrogen is will be triggered.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1022130850


##########
lang/csharp/README.md:
##########
@@ -39,6 +39,36 @@ Install-Package Apache.Avro
 2. By updating the versions in our libraries, we require users of the library to update to a version equal to or greater than the version we reference. For example, if a user were to reference an older version of Newtonsoft.Json, they would be forced to update to a newer version before they could use a new version of the Avro library.
 In short, we should only update the version of the dependencies in our libraries if we absolutely must for functionality that we require. We leave it up to the users of the library as to whether or not they want the latest and greatest of a particularly dependency. We're only going to require the bare minimum.
 
+## MSBuild Avro Generator Task
+
+MSBuild task `AvroGenTask` can be used to compile avro schema or protocol files from `.csproj`, without explicitly calling `avrogen` tool binary.
+
+Example:
+
+```
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net6.0</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <SchemaFiles Include="schemas/**/*.avsc" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Apache.Avro" Version="1.11.2 />
+    <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
+  </ItemGroup>
+
+  <Target Name="AvroGenerate" BeforeTargets="CoreCompile">
+    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" />

Review Comment:
   This is the same way avrogen would work. The cs generation will happen every time  this task is triggered. To implement dependencies, basic mechanism can be implemented, using Inputs and Outputs props of Target.
   
   SInce the schema -> cs mapping is not 1 to 1, implementing the dependencies inside the codegen library is not trivial (as it is currently implemented). This PR simply let the user use an MSBuild task tinstead of calling avrogen. Avrogen as a tool has a limitation that it relies on a specific SDK version. E.g until the net7 version of avrogen is not released, avrogen cannot be used in a net7 only NET SDK container.
   
   Using MSBuild tasks are solving that issue, since the MSBuild task package is targeting netstandard2.0.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] KalleOlaviNiemitalo commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "KalleOlaviNiemitalo (via GitHub)" <gi...@apache.org>.
KalleOlaviNiemitalo commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1109909560


##########
lang/csharp/README.md:
##########
@@ -63,7 +63,12 @@ Example:
   </ItemGroup>
 
   <Target Name="AvroGenerate" BeforeTargets="CoreCompile">
-    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" />
+    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" >
+      <!-- bind generated files task output -->
+      <Output ItemName="GeneratedCodeFiles" TaskParameter="GeneratedFiles" />

Review Comment:
   When 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "zcsizmadia (via GitHub)" <gi...@apache.org>.
zcsizmadia commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1109932456


##########
lang/csharp/README.md:
##########
@@ -63,7 +63,12 @@ Example:
   </ItemGroup>
 
   <Target Name="AvroGenerate" BeforeTargets="CoreCompile">
-    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" />
+    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" >
+      <!-- bind generated files task output -->
+      <Output ItemName="GeneratedCodeFiles" TaskParameter="GeneratedFiles" />
+    </AvroGenTask>
+    <!-- displays generated files in build logs -->
+    <Message Text="Generated: %(GeneratedCodeFiles.Identity)" Importance="normal" />

Review Comment:
   The generated files are always a realtive path to the OutDir, and the path starting with OutDir. Havent tried it, but `WriteTypes` just combines OutDir with the extra path (namespaces). There is no conversion to absolute path, so that relative path will be  returned in the `GeneratedFiles` list.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on PR #1966:
URL: https://github.com/apache/avro/pull/1966#issuecomment-1314126428

   @RyanSkraba This revives the already exeisting Avro.msbuild project. Adds unit testing for the MSBUild task and generates the proper nuget package, e.g. `Apache.Avro.MSBuild.1.11.2.nupkg`. If the PR is merged, in the next release this nupkg shoudl be pushed to nuget as well.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] KalleOlaviNiemitalo commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
KalleOlaviNiemitalo commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1022028943


##########
lang/csharp/README.md:
##########
@@ -39,6 +39,36 @@ Install-Package Apache.Avro
 2. By updating the versions in our libraries, we require users of the library to update to a version equal to or greater than the version we reference. For example, if a user were to reference an older version of Newtonsoft.Json, they would be forced to update to a newer version before they could use a new version of the Avro library.
 In short, we should only update the version of the dependencies in our libraries if we absolutely must for functionality that we require. We leave it up to the users of the library as to whether or not they want the latest and greatest of a particularly dependency. We're only going to require the bare minimum.
 
+## MSBuild Avro Generator Task
+
+MSBuild task `AvroGenTask` can be used to compile avro schema or protocol files from `.csproj`, without explicitly calling `avrogen` tool binary.
+
+Example:
+
+```
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net6.0</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <SchemaFiles Include="schemas/**/*.avsc" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Apache.Avro" Version="1.11.2 />
+    <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
+  </ItemGroup>
+
+  <Target Name="AvroGenerate" BeforeTargets="CoreCompile">
+    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" />

Review Comment:
   Does this work if the generated C# files do not already exist before the build?  I think the .NET SDK expands the default item globs before it runs any targets, and the generated files won't then be included in the `Compile` item type, causing the first build to generate the files OK but not compile them, which would then result in undefined-identifier errors in other source files.
   
   For that reason, and for skipping avrogen in incremental builds if the schema files have not been changed, it might be good to provide a mode that generates one C# file per avsc input file, or even one C# file per run, rather than one per named schema.  That way, the names of the generated files would not depend on the content of the avsc files, and the project would be able to include them in `Compile` regardless of whether the files have been generated already.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1022135052


##########
lang/csharp/README.md:
##########
@@ -39,6 +39,36 @@ Install-Package Apache.Avro
 2. By updating the versions in our libraries, we require users of the library to update to a version equal to or greater than the version we reference. For example, if a user were to reference an older version of Newtonsoft.Json, they would be forced to update to a newer version before they could use a new version of the Avro library.
 In short, we should only update the version of the dependencies in our libraries if we absolutely must for functionality that we require. We leave it up to the users of the library as to whether or not they want the latest and greatest of a particularly dependency. We're only going to require the bare minimum.
 
+## MSBuild Avro Generator Task
+
+MSBuild task `AvroGenTask` can be used to compile avro schema or protocol files from `.csproj`, without explicitly calling `avrogen` tool binary.
+
+Example:
+
+```
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net6.0</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <SchemaFiles Include="schemas/**/*.avsc" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Apache.Avro" Version="1.11.2 />
+    <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
+  </ItemGroup>
+
+  <Target Name="AvroGenerate" BeforeTargets="CoreCompile">
+    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" />

Review Comment:
   Here is an example how  dependencies and can be solved via Target:
   
   ```
   <Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
       <OutputType>Exe</OutputType>
       <TargetFramework>net6.0</TargetFramework>
       <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
     </PropertyGroup>
   
     <ItemGroup>
       <SchemaFiles Include="schemas/**/*.avsc" />
     </ItemGroup>
   
     <ItemGroup>
       <PackageReference Include="Apache.Avro" Version="1.11.2 />
       <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
     </ItemGroup>
   
     <Target Name="AvroGenerate" BeforeTargets="BeforeRebuild;BeforeBuild" Inputs="@(SchemaFiles)" Outputs="generated/.AvroGenSuccess" >
       <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" /> <!-- Avro code geneartion -->
       <WriteLinesToFile File="generated/.AvroGenSuccess" Overwrite="true" Lines="%(SchemaFiles.Identity)" />
   
       <!-- Generate code file list after avrogen -->
       <ItemGroup>
         <Compile Include="generated/**/*.cs" Condition="Exists('generated/.AvroGenSuccess')" />
       </ItemGroup>
     </Target>
   
     <Target Name="AvroGenClean" BeforeTargets="BeforeClean">
       <RemoveDir Directories="generated" />
     </Target>
   
     <ItemGroup>
       <Compile Include="generated/**/*.cs" Condition="Exists('generated/.AvroGenSuccess')" />
     </ItemGroup>
   
   </Project>
   ```
   
   The first time avrogen runs, at completion a success marker file is created. Next time MSBuild will compare the timestamp of all input schema files and the success file, if any of the input schemas were changed since the last success, the files are re-avrogen'd. If not, no avrogen is will be triggered.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] alexrosenfeld10 commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1172745843


##########
lang/csharp/src/apache/msbuild/AvroGenTask.cs:
##########
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.IO;
+using System.Linq;
+using System.Collections.Generic;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Avro.msbuild
+{
+    public class AvroGenTask : Task
+    {
+        public override bool Execute()
+        {
+            try
+            {
+                Dictionary<string, string> namespaceMapping = new Dictionary<string, string>();
+
+                MessageImportance messageImportance = string.IsNullOrEmpty(MessageLevel) ? 
+                    MessageImportance.Normal :
+                    (MessageImportance)Enum.Parse(typeof(MessageImportance), MessageLevel);
+
+                var codegen = new CodeGen();
+
+                if (!string.IsNullOrEmpty(NamespaceMapping))
+                {
+                    foreach(var mapping in NamespaceMapping.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
+                    {
+                        var parts = mapping.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
+                        if (parts.Length != 2)
+                        {
+                            throw new ArgumentException("Malformed namespace mapping. Required format is \"avro.namespace:csharp.namespace\"");
+                        }
+                        namespaceMapping[parts[0]] = parts[1];
+                    }
+                }
+
+                if (SchemaFiles != null)
+                {
+                    foreach (var schemaFile in SchemaFiles)
+                    {
+                        var schemaText = System.IO.File.ReadAllText(schemaFile.ItemSpec);
+                        codegen.AddSchema(schemaText, namespaceMapping);

Review Comment:
   (btw, full transparency, I'm asking the same question at https://stackoverflow.com/questions/76065680/avro-c-sharp-generate-classes-using-types-defined-across-multiple-schema-files. Apologies if this isn't appropriate for a PR review, it's on the borderline as adding support for multi-file schemas would be good to add here)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] KalleOlaviNiemitalo commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "KalleOlaviNiemitalo (via GitHub)" <gi...@apache.org>.
KalleOlaviNiemitalo commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1109911894


##########
lang/csharp/README.md:
##########
@@ -63,7 +63,12 @@ Example:
   </ItemGroup>
 
   <Target Name="AvroGenerate" BeforeTargets="CoreCompile">
-    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" />
+    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" >
+      <!-- bind generated files task output -->
+      <Output ItemName="GeneratedCodeFiles" TaskParameter="GeneratedFiles" />
+    </AvroGenTask>
+    <!-- displays generated files in build logs -->
+    <Message Text="Generated: %(GeneratedCodeFiles.Identity)" Importance="normal" />

Review Comment:
   When you use `OutDir="generated"`, the resulting `%(GeneratedCodeFiles.Identity)` will be a relative path that starts with "generated" rather than a full path, right? If so, then that's fine, but is it what you intended?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1022135052


##########
lang/csharp/README.md:
##########
@@ -39,6 +39,36 @@ Install-Package Apache.Avro
 2. By updating the versions in our libraries, we require users of the library to update to a version equal to or greater than the version we reference. For example, if a user were to reference an older version of Newtonsoft.Json, they would be forced to update to a newer version before they could use a new version of the Avro library.
 In short, we should only update the version of the dependencies in our libraries if we absolutely must for functionality that we require. We leave it up to the users of the library as to whether or not they want the latest and greatest of a particularly dependency. We're only going to require the bare minimum.
 
+## MSBuild Avro Generator Task
+
+MSBuild task `AvroGenTask` can be used to compile avro schema or protocol files from `.csproj`, without explicitly calling `avrogen` tool binary.
+
+Example:
+
+```
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net6.0</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <SchemaFiles Include="schemas/**/*.avsc" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Apache.Avro" Version="1.11.2 />
+    <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
+  </ItemGroup>
+
+  <Target Name="AvroGenerate" BeforeTargets="CoreCompile">
+    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" />

Review Comment:
   Here is an example how  dependencies and can be solved via Target:
   
   ```
   <Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
       <OutputType>Exe</OutputType>
       <TargetFramework>net6.0</TargetFramework>
     </PropertyGroup>
   
     <ItemGroup>
       <SchemaFiles Include="schemas/**/*.avsc" />
     </ItemGroup>
   
     <ItemGroup>
       <PackageReference Include="Apache.Avro" Version="1.11.2 />
       <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
     </ItemGroup>
   
     <Target Name="AvroGenerate" BeforeTargets="BeforeRebuild;BeforeBuild" Inputs="@(SchemaFiles)" Outputs="generated/.AvroGenSuccess" >
       <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" /> <!-- Avro code geneartion -->
       <WriteLinesToFile File="generated/.AvroGenSuccess" Overwrite="true" Lines="%(SchemaFiles.Identity)" />
   
       <!-- Generate code file list after avrogen -->
       <ItemGroup>
         <Compile Include="generated/**/*.cs" Condition="Exists('generated/.AvroGenSuccess')" />
       </ItemGroup>
     </Target>
   
     <Target Name="AvroGenClean" BeforeTargets="BeforeClean">
       <RemoveDir Directories="generated" />
     </Target>
   
     <ItemGroup>
       <Compile Include="generated/**/*.cs" Condition="Exists('generated/.AvroGenSuccess')" />
     </ItemGroup>
   
   </Project>
   ```
   
   The first time avrogen runs, at completion a success marker file is created. Next time MSBuild will compare the timestamp of all input schema files and the success file, if any of the input schemas were changed since the last success, the files are re-avrogen'd. If not, no avrogen is will be triggered.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1022135052


##########
lang/csharp/README.md:
##########
@@ -39,6 +39,36 @@ Install-Package Apache.Avro
 2. By updating the versions in our libraries, we require users of the library to update to a version equal to or greater than the version we reference. For example, if a user were to reference an older version of Newtonsoft.Json, they would be forced to update to a newer version before they could use a new version of the Avro library.
 In short, we should only update the version of the dependencies in our libraries if we absolutely must for functionality that we require. We leave it up to the users of the library as to whether or not they want the latest and greatest of a particularly dependency. We're only going to require the bare minimum.
 
+## MSBuild Avro Generator Task
+
+MSBuild task `AvroGenTask` can be used to compile avro schema or protocol files from `.csproj`, without explicitly calling `avrogen` tool binary.
+
+Example:
+
+```
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net6.0</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <SchemaFiles Include="schemas/**/*.avsc" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Apache.Avro" Version="1.11.2 />
+    <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
+  </ItemGroup>
+
+  <Target Name="AvroGenerate" BeforeTargets="CoreCompile">
+    <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" />

Review Comment:
   Here is an example how  dependencies can be solved via Target:
   
   ```
   <Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
       <OutputType>Exe</OutputType>
       <TargetFramework>net6.0</TargetFramework>
     </PropertyGroup>
     <ItemGroup>
       <SchemaFiles Include="schemas/**/*.avsc" />
     </ItemGroup>
     <ItemGroup>
       <PackageReference Include="Apache.Avro" Version="1.11.2 />
       <PackageReference Include="Apache.Avro.MSBuild" Version="1.11.2" PrivateAssets="All" />
     </ItemGroup>
     <Target Name="AvroGenerate" BeforeTargets="CoreCompile" Inputs="@(SchemaFiles)" Outputs="generated/.AvroGenSuccess" >
       <AvroGenTask SchemaFiles="@(SchemaFiles)" OutDir="generated" /> <!-- Avro code geneartion -->
       <WriteLinesToFile File="generated/.AvroGenSuccess" Overwrite="true" Lines="%(SchemaFiles.Identity)" />
     </Target>
   </Project>
   ```
   
   The first time avrogen runs, at completion a success marker file is created. Next time MSBuild will compare the timestamp of all input schema files and the success file, if any of the input schemas were changed since the last success, the files are re-avrogen'd. If not, no avrogen is will be triggered.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] zcsizmadia commented on pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "zcsizmadia (via GitHub)" <gi...@apache.org>.
zcsizmadia commented on PR #1966:
URL: https://github.com/apache/avro/pull/1966#issuecomment-1435990819

   MSBuild does not use the NuGet cache to find dependencies. This is a limitation msbuild and nuget still has. Yhis means that you need to create a "fat" package and include the dependencies for the custom msbuild. However the dependencies are Avro.dll and everything AVro.dll depends on. The Avro MSBuild task nupkg will include the common LICENSE file from the root of the csharp source tree, which is enough.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [avro] alexrosenfeld10 commented on a diff in pull request #1966: AVRO-3673: Add MSBuild AvroGenTask

Posted by "alexrosenfeld10 (via GitHub)" <gi...@apache.org>.
alexrosenfeld10 commented on code in PR #1966:
URL: https://github.com/apache/avro/pull/1966#discussion_r1172695000


##########
lang/csharp/src/apache/msbuild/AvroGenTask.cs:
##########
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.IO;
+using System.Linq;
+using System.Collections.Generic;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Avro.msbuild
+{
+    public class AvroGenTask : Task
+    {
+        public override bool Execute()
+        {
+            try
+            {
+                Dictionary<string, string> namespaceMapping = new Dictionary<string, string>();
+
+                MessageImportance messageImportance = string.IsNullOrEmpty(MessageLevel) ? 
+                    MessageImportance.Normal :
+                    (MessageImportance)Enum.Parse(typeof(MessageImportance), MessageLevel);
+
+                var codegen = new CodeGen();
+
+                if (!string.IsNullOrEmpty(NamespaceMapping))
+                {
+                    foreach(var mapping in NamespaceMapping.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
+                    {
+                        var parts = mapping.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
+                        if (parts.Length != 2)
+                        {
+                            throw new ArgumentException("Malformed namespace mapping. Required format is \"avro.namespace:csharp.namespace\"");
+                        }
+                        namespaceMapping[parts[0]] = parts[1];
+                    }
+                }
+
+                if (SchemaFiles != null)
+                {
+                    foreach (var schemaFile in SchemaFiles)
+                    {
+                        var schemaText = System.IO.File.ReadAllText(schemaFile.ItemSpec);
+                        codegen.AddSchema(schemaText, namespaceMapping);

Review Comment:
   Even if I inline the shared enum definition, like so:
   
   ```csharp
           var codeCompileUnit = new CodeGen
           {
               Schemas =
               {
                   Schema.Parse("""
   {
     "name": "PlanetEnum",
     "namespace": "My.Model",
     "type": "enum",
     "symbols": [
       "Earth",
       "Mars"
     ]
   }
   """),
                   Schema.Parse(schemaText)
               },
           }.GenerateCode();
   ```
   
   it fails with:
   ```text
   Avro.SchemaParseException: Undefined name: My.Model.PlanetEnum at 'fields[0].type'
      at Avro.Schema.ParseJson(JToken jtok, SchemaNames names, String encspace)
      at Avro.RecordSchema.createField(JToken jfield, Int32 pos, SchemaNames names, String encspace)
      at Avro.RecordSchema.NewInstance(Type type, JToken jtok, PropertyMap props, SchemaNames names, String encspace)
      at Avro.NamedSchema.NewInstance(JObject jo, PropertyMap props, SchemaNames names, String encspace)
      at Avro.Schema.ParseJson(JToken jtok, SchemaNames names, String encspace)
      at Avro.Schema.Parse(String json, SchemaNames names, String encspace)
      at Avro.Schema.Parse(String json)
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-3673: Add MSBuild AvroGenTask [avro]

Posted by "zcsizmadia (via GitHub)" <gi...@apache.org>.
zcsizmadia closed pull request #1966: AVRO-3673: Add MSBuild AvroGenTask
URL: https://github.com/apache/avro/pull/1966


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org