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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to