-
-
Notifications
You must be signed in to change notification settings - Fork 64
Fix MSBuild task so that the generated code is included in the compilation #745
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
Changes from 9 commits
39a6c62
1acef6c
fc44b73
ccd027a
d822ae2
11e413f
de25ec6
e914332
dc4ea9e
e012625
5ec0331
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,17 +1,22 @@ | ||||||||
| ## MSBuild Tasks for Refitter | ||||||||
| # MSBuild Tasks for Refitter | ||||||||
|
|
||||||||
| Refitter is available as custom MSBuild tasks that includes the Refitter CLI executable for generating a REST API Client using the [Refit](https://github.com/reactiveui/refit) library. Refitter can generate the Refit interface from OpenAPI specifications. Refitter could format the generated Refit interface to be managed by [Apizr](https://www.apizr.net) (v6+) and generate some registration helpers too. | ||||||||
|
|
||||||||
| The MSBuild package includes a custom `.target` file which executes the `RefitterGenerateTask` custom task and looks something like this: | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: .target → .targets File extension should be .targets. Apply: -The MSBuild package includes a custom `.target` file which executes the `RefitterGenerateTask` custom task and looks something like this:
+The MSBuild package includes a custom `.targets` file which executes the `RefitterGenerateTask` custom task and looks like this:📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
| ```xml | ||||||||
| <Target Name="Refitter" BeforeTargets="BeforeBuild"> | ||||||||
| <UsingTask TaskName="RefitterGenerateTask" | ||||||||
| AssemblyFile="$(MSBuildThisFileDirectory)Refitter.MSBuild.dll" | ||||||||
| Condition="Exists('$(MSBuildThisFileDirectory)Refitter.MSBuild.dll')" /> | ||||||||
|
christianhelle marked this conversation as resolved.
|
||||||||
| <Target Name="RefitterGenerate" BeforeTargets="BeforeCompile"> | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use CoreCompile (and CompileDesignTime) instead of BeforeCompile BeforeCompile isn’t a standard target; your task may never run. Hook into CoreCompile; add CompileDesignTime so IDE design-time builds see generated files. Apply: -<Target Name="RefitterGenerate" BeforeTargets="BeforeCompile">
+<Target Name="RefitterGenerate" BeforeTargets="CoreCompile;CompileDesignTime"
+ Condition=" '$(IsCrossTargetingBuild)' != 'true' and Exists('$(MSBuildThisFileDirectory)Refitter.MSBuild.dll')">📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| <RefitterGenerateTask ProjectFileDirectory="$(MSBuildProjectDirectory)" | ||||||||
| DisableLogging="$(RefitterNoLogging)"/> | ||||||||
| DisableLogging="$(RefitterNoLogging)"> | ||||||||
| <Output TaskParameter="GeneratedFiles" ItemName="RefitterGeneratedFiles" /> | ||||||||
| </RefitterGenerateTask> | ||||||||
| <ItemGroup> | ||||||||
| <Compile Include="**/*.cs" /> | ||||||||
| <Compile Include="@(RefitterGeneratedFiles)" /> | ||||||||
| </ItemGroup> | ||||||||
| </Target> | ||||||||
| </Target> | ||||||||
| ``` | ||||||||
|
|
||||||||
| The `RefitterGenerateTask` task will scan the project folder for `.refitter` files and executes them all. By default, telemetry collection is enabled, and to opt-out of it you must specify `<RefitterNoLogging>true</RefitterNoLogging>` in the `.csproj` `<PropertyGroup>` | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,16 @@ | ||||||||||||||
| <Project> | ||||||||||||||
|
|
||||||||||||||
| <Target Name="Refitter" BeforeTargets="BeforeBuild"> | ||||||||||||||
| <UsingTask TaskName="RefitterGenerateTask" | ||||||||||||||
| AssemblyFile="$(MSBuildThisFileDirectory)Refitter.MSBuild.dll" | ||||||||||||||
| Condition="Exists('$(MSBuildThisFileDirectory)Refitter.MSBuild.dll')" /> | ||||||||||||||
|
Comment on lines
+3
to
+5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fully qualify TaskName for reliability Avoid ambiguous or unresolvable types. Apply: - <UsingTask TaskName="RefitterGenerateTask"
+ <UsingTask TaskName="Refitter.MSBuild.RefitterGenerateTask"
AssemblyFile="$(MSBuildThisFileDirectory)Refitter.MSBuild.dll"
Condition="Exists('$(MSBuildThisFileDirectory)Refitter.MSBuild.dll')" />📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| <Target Name="RefitterGenerate" BeforeTargets="BeforeCompile"> | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Target doesn’t run: BeforeCompile isn’t a standard hook Switch to CoreCompile; add CompileDesignTime for IDEs; also guard with a Condition to avoid failures when the DLL is missing and to skip the outer cross-targeting build. Apply: - <Target Name="RefitterGenerate" BeforeTargets="BeforeCompile">
+ <Target Name="RefitterGenerate" BeforeTargets="CoreCompile;CompileDesignTime"
+ Condition=" '$(IsCrossTargetingBuild)' != 'true' and Exists('$(MSBuildThisFileDirectory)Refitter.MSBuild.dll')">📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| <RefitterGenerateTask ProjectFileDirectory="$(MSBuildProjectDirectory)" | ||||||||||||||
| DisableLogging="$(RefitterNoLogging)"/> | ||||||||||||||
| DisableLogging="$(RefitterNoLogging)"> | ||||||||||||||
| <Output TaskParameter="GeneratedFiles" ItemName="RefitterGeneratedFiles" /> | ||||||||||||||
| </RefitterGenerateTask> | ||||||||||||||
| <ItemGroup> | ||||||||||||||
| <Compile Include="**/*.cs" /> | ||||||||||||||
| <Compile Include="@(RefitterGeneratedFiles)" /> | ||||||||||||||
| </ItemGroup> | ||||||||||||||
| </Target> | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Diagnostics; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Reflection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Text.RegularExpressions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.Build.Framework; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using MSBuildTask = Microsoft.Build.Utilities.Task; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace Refitter.MSBuild; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -10,6 +12,9 @@ public class RefitterGenerateTask : MSBuildTask | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public bool DisableLogging { get; set; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [Output] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public ITaskItem[] GeneratedFiles { get; set; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public override bool Execute() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TryLogCommandLine($"Starting {nameof(RefitterGenerateTask)}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -22,40 +27,75 @@ public override bool Execute() | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TryLogCommandLine($"Found {files.Length} .refitter files..."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var generatedFiles = new List<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foreach (var file in files) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TryLogCommandLine($"Processing {file}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TryExecuteRefitter(file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var generated = TryExecuteRefitter(file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (generated != null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| generatedFiles.AddRange(generated); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GeneratedFiles = generatedFiles.Select(f => new Microsoft.Build.Utilities.TaskItem(f)).ToArray(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
christianhelle marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TryLogCommandLine($"Generated {GeneratedFiles.Length} files"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
45
to
46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Return failure when errors are logged MSBuild tasks should return false on error to stop the build. - return true;
+ return !Log.HasLoggedErrors;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void TryExecuteRefitter(string file) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private List<string>? TryExecuteRefitter(string file) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StartProcess(file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return StartProcess(file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| catch (Exception e) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TryLogErrorFromException(e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void StartProcess(string file) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private List<string> StartProcess(string file) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // First, determine what files will be generated by parsing the .refitter file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var expectedFiles = GetExpectedGeneratedFiles(file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var assembly = Assembly.GetExecutingAssembly(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var packageFolder = Path.GetDirectoryName(assembly.Location); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var seperator = Path.DirectorySeparatorChar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Try multiple possible locations for the Refitter CLI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var refitterDll = $"{packageFolder}{seperator}..{seperator}refitter.dll"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // For development scenarios, try relative to the MSBuild project location | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use ArgumentList and proper quoting; fix typo in variable name. String-building Arguments will break with spaces and invites subtle bugs. Prefer ProcessStartInfo.ArgumentList. Also rename 'seperator' → 'separator'. - var packageFolder = Path.GetDirectoryName(assembly.Location);
- var seperator = Path.DirectorySeparatorChar;
+ var packageFolder = Path.GetDirectoryName(assembly.Location);
+ var separator = Path.DirectorySeparatorChar;
@@
- var refitterDll = $"{packageFolder}{seperator}..{seperator}refitter.dll";
+ var refitterDll = $"{packageFolder}{separator}..{separator}refitter.dll";And below (see next comment) replace Arguments with ArgumentList. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!File.Exists(refitterDll)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| refitterDll = $"{packageFolder}{seperator}..{seperator}..{seperator}..{seperator}Refitter{seperator}bin{seperator}Debug{seperator}net8.0{seperator}refitter.dll"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // If still not found, try in the current project directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!File.Exists(refitterDll)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| refitterDll = Path.Combine(ProjectFileDirectory!, "..", "..", "src", "Refitter", "bin", "Debug", "net8.0", "refitter.dll"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var args = $"{refitterDll} --settings-file {file}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (DisableLogging) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args += " --no-logging"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
christianhelle marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!File.Exists(refitterDll)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TryLogError($"Refitter CLI not found at: {refitterDll}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TryLogError($"Assembly location: {assembly.Location}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TryLogError($"Package folder: {packageFolder}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new List<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+75
to
+82
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Treat missing CLI as a hard failure. Returning an empty list hides the root cause and keeps the build green. - TryLogError($"Refitter CLI not found at: {refitterDll}");
- TryLogError($"Assembly location: {assembly.Location}");
- TryLogError($"Package folder: {packageFolder}");
- return new List<string>();
+ TryLogError($"Refitter CLI not found at: {refitterDll}");
+ TryLogError($"Assembly location: {assembly.Location}");
+ TryLogError($"Package folder: {packageFolder}");
+ throw new FileNotFoundException("Refitter CLI not found.", refitterDll);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TryLogCommandLine($"Starting dotnet {args}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using var process = new Process | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -79,6 +119,84 @@ private void StartProcess(string file) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.BeginErrorReadLine(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.BeginOutputReadLine(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.WaitForExit(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Return the list of files that should have been generated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return expectedFiles.Where(File.Exists).ToList(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private List<string> GetExpectedGeneratedFiles(string refitterFilePath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var refitterFileDirectory = Path.GetDirectoryName(refitterFilePath) ?? string.Empty; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var refitterContent = File.ReadAllText(refitterFilePath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Parse JSON properties using simple regex patterns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var outputFolder = ExtractJsonStringValue(refitterContent, "outputFolder"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var outputFilename = ExtractJsonStringValue(refitterContent, "outputFilename"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var generateMultipleFiles = ExtractJsonBoolValue(refitterContent, "generateMultipleFiles"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var contractsOutputFolder = ExtractJsonStringValue(refitterContent, "contractsOutputFolder"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var hasDependencyInjectionSettings = refitterContent.Contains("\"dependencyInjectionSettings\""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // If contractsOutputFolder is specified, automatically enable multiple files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!string.IsNullOrWhiteSpace(contractsOutputFolder)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| generateMultipleFiles = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Default output filename based on .refitter filename if not specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (string.IsNullOrWhiteSpace(outputFilename)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var refitterFileName = Path.GetFileNameWithoutExtension(refitterFilePath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputFilename = $"{refitterFileName}.cs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var generatedFiles = new List<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (generateMultipleFiles) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Multiple files mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var baseOutputFolder = !string.IsNullOrWhiteSpace(outputFolder) ? outputFolder : "./Generated"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var interfaceOutputPath = Path.GetFullPath(Path.Combine(refitterFileDirectory, baseOutputFolder, "RefitInterfaces.cs")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var contractsOutputPath = Path.GetFullPath(Path.Combine(refitterFileDirectory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| !string.IsNullOrWhiteSpace(contractsOutputFolder) ? contractsOutputFolder : baseOutputFolder, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Contracts.cs")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var diOutputPath = Path.GetFullPath(Path.Combine(refitterFileDirectory, baseOutputFolder, "DependencyInjection.cs")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| generatedFiles.Add(interfaceOutputPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| generatedFiles.Add(contractsOutputPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // DependencyInjection.cs is only generated if dependencyInjectionSettings are specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (hasDependencyInjectionSettings) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| generatedFiles.Add(diOutputPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Single file mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string outputPath; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!string.IsNullOrWhiteSpace(outputFolder)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // outputFolder is specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputPath = Path.GetFullPath(Path.Combine(refitterFileDirectory, outputFolder, outputFilename)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // No outputFolder specified - generate in current directory (default behavior) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputPath = Path.GetFullPath(Path.Combine(refitterFileDirectory, outputFilename)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| generatedFiles.Add(outputPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TryLogCommandLine($"Expected generated files: {string.Join(", ", generatedFiles)}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return generatedFiles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| catch (Exception ex) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TryLogError($"Error parsing .refitter file {refitterFilePath}: {ex.Message}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new List<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
christianhelle marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void TryLogErrorFromException(Exception e) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -116,4 +234,22 @@ private void TryLogError(string text) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ignore | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static string? ExtractJsonStringValue(string json, string propertyName) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Simple regex to extract string values from JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Pattern: "propertyName": "value" or "propertyName":"value" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var pattern = $@"""{Regex.Escape(propertyName)}""\s*:\s*""([^""]*)"""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var match = Regex.Match(json, pattern, RegexOptions.IgnoreCase); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return match.Success ? match.Groups[1].Value : null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
christianhelle marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static bool ExtractJsonBoolValue(string json, string propertyName) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Simple regex to extract boolean values from JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Pattern: "propertyName": true or "propertyName":false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var pattern = $@"""{Regex.Escape(propertyName)}""\s*:\s*(true|false)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var match = Regex.Match(json, pattern, RegexOptions.IgnoreCase); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return match.Success && string.Equals(match.Groups[1].Value, "true", StringComparison.OrdinalIgnoreCase); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,17 @@ | ||
| Remove-Item bin -Force -Recurse | ||
| Remove-Item obj -Force -Recurse | ||
| dotnet build-server shutdown | ||
| nuget locals global-packages -clear | ||
| Remove-Item ./refitter.msbuild -Recurse -Force | ||
| dotnet nuget locals global-packages --clear | ||
| Remove-Item Refitter.MSBuild.*.nupkg -Force | ||
| Remove-Item Petstore.cs | ||
| dotnet restore ../../src/Refitter.sln | ||
| dotnet clean -c release ../../src/Refitter.sln | ||
| dotnet build -c release ../../src/Refitter/Refitter.csproj | ||
| dotnet build -c release ../../src/Refitter.MSBuild/Refitter.MSBuild.csproj | ||
| dotnet pack -c release ../../src/Refitter.MSBuild/Refitter.MSBuild.csproj -o . | ||
| nuget add .\Refitter.MSBuild.1.0.0.nupkg -source . | ||
| dotnet add package .\Refitter.MSBuild.1.0.0.nupkg --source . | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invalid command: dotnet add package does not accept a .nupkg path. This will fail. Use the package ID and point to the folder as a source (the pack step already put the .nupkg in .). -dotnet add package .\Refitter.MSBuild.1.0.0.nupkg --source .
+# Register current folder as a source (optional if you pass --source . each time)
+# dotnet nuget add source . --name LocalRefitter
+dotnet add package Refitter.MSBuild --source .🤖 Prompt for AI Agents |
||
| dotnet restore | ||
| dotnet add package Refitter.MSBuild -s . | ||
| dotnet build -v d -filelogger | ||
| dotnet add package Refitter.MSBuild --source . | ||
|
christianhelle marked this conversation as resolved.
|
||
| dotnet run -v d -filelogger | ||
|
christianhelle marked this conversation as resolved.
|
||
| dotnet remove package Refitter.MSBuild | ||
| Remove-Item Refitter.MSBuild.*.nupkg -Force | ||
Uh oh!
There was an error while loading. Please reload this page.