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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]