Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): bump Microsoft.CodeAnalysis.Analyzers from 3.3.4 to 3.11.0 #418

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/generated/KiotaGenerated.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" ExcludeAssets="runtime" />
</ItemGroup>

<Target Name="DoSthAfterPublish1" AfterTargets="Publish">
Expand Down
46 changes: 21 additions & 25 deletions src/generated/KiotaVersionGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;

namespace KiotaGenerated;

[Generator]
public class KiotaVersionGenerator : ISourceGenerator
public class KiotaVersionGenerator : IIncrementalGenerator
{
public void Execute(GeneratorExecutionContext context)
public void Initialize(IncrementalGeneratorInitializationContext context)
{
var mainSyntaxTree = context.Compilation.SyntaxTrees
.First(static x => x.HasCompilationUnitRoot);

var projectDirectory = Path.GetDirectoryName(mainSyntaxTree.FilePath);

var version = "unknown";
try
{
XmlDocument csproj = new XmlDocument();
projectDirectory = Path.Combine(projectDirectory, "..", "..", "..", "..", "Directory.Build.props");
csproj.Load(projectDirectory);
version = csproj.GetElementsByTagName("VersionPrefix")[0].InnerText;
}
catch(Exception e)
context.RegisterSourceOutput(context.CompilationProvider, (spc, compilation) =>
{
throw new FileNotFoundException($"KiotaVersionGenerator expanded in an invalid project, missing 'Directory.Build.props' file in the following directory {projectDirectory}", e);
}
var projectDirectory = Path.GetDirectoryName(compilation.SyntaxTrees.First().FilePath);

string source = $@"// <auto-generated/>
try
{
XmlDocument csproj = new XmlDocument();
projectDirectory = Path.Combine(projectDirectory, "..", "..", "..", "..", "Directory.Build.props");
csproj.Load(projectDirectory);
var version = csproj.GetElementsByTagName("VersionPrefix")[0].InnerText;
string source = $@"// <auto-generated/>
namespace Microsoft.Kiota.Http.Generated
{{
/// <summary>
Expand All @@ -48,12 +42,14 @@ public static string Current()
}}
";

// Add the source code to the compilation
context.AddSource($"KiotaVersion.g.cs", source);
// Add the source code to the compilation
spc.AddSource($"KiotaVersion.g.cs", SourceText.From(source, Encoding.UTF8));
}
catch(Exception e)
{
throw new FileNotFoundException($"KiotaVersionGenerator expanded in an invalid project, missing 'Directory.Build.props' file in the following directory {projectDirectory}", e);
}
});
}

public void Initialize(GeneratorInitializationContext context)
{
// No initialization required for this one
}
}
Loading