Skip to content

Commit

Permalink
Fix #4 by adding options
Browse files Browse the repository at this point in the history
  • Loading branch information
timheuer committed Dec 1, 2023
1 parent f23e520 commit f513ef0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

# .NET Aspire Manifest generator
A dumb little utility to quickly generate a deployment manifest from VS solution explorer.

I honestly don't expect anyone to use this beyond myself and a few other team members for quick validation purposes in Visual Studio, demo purposes, etc. so with that it comes with the "works on my machine" level of quality guarantee.
5 changes: 3 additions & 2 deletions src/AspireManifestGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Options\General.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Commands\ManifestGen.cs" />
<Compile Include="AspireManifestGenPackage.cs" />
Expand All @@ -61,8 +62,8 @@
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
<Generator>VsixManifestGenerator</Generator>
<SubType>Designer</SubType>
<Generator>VsixManifestGenerator</Generator>
</None>
<Content Include="Resources\Icon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
4 changes: 4 additions & 0 deletions src/AspireManifestGenPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
global using Task = System.Threading.Tasks.Task;
using System.Runtime.InteropServices;
using System.Threading;
using AspireManifestGen.Options;

namespace AspireManifestGen;
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[Guid(PackageGuids.AspireManifestGenString)]
[ProvideOptionPage(typeof(OptionsProvider.GeneralOptions), "Projects and Solutions", ".NET Aspire", 0, 0, true)]
[ProvideProfile(typeof(OptionsProvider.GeneralOptions), "Projects and Solutions", ".NET Aspire", 0, 0, true)]

public sealed class AspireManifestGenPackage : ToolkitPackage
{
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
Expand Down
24 changes: 20 additions & 4 deletions src/Commands/ManifestGen.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using AspireManifestGen.Options;
using System.Diagnostics;
using System.IO;

namespace AspireManifestGen;
Expand All @@ -11,12 +12,26 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
var project = await VS.Solutions.GetActiveProjectAsync();
var projectPath = Path.GetDirectoryName(project.FullPath);

var options = await General.GetLiveInstanceAsync();
// get temp path to a file and rename the file extension to .json extension
var tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName().Replace(".", "") + ".json");
//var tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName().Replace(".", "") + ".json");

var manifestPath = string.Empty;

if (options.UseTempFile)
{
// get temp path to a file and rename the file extension to .json extension
manifestPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName().Replace(".", "") + ".json");
}
else
{
manifestPath = Path.Combine(projectPath, options.DefaultName);
}

Process process = new Process();
process.StartInfo.WorkingDirectory = projectPath;
process.StartInfo.FileName = "dotnet.exe";
process.StartInfo.Arguments = $"msbuild /t:GenerateAspireManifest /p:AspireManifestPublishOutputPath={tempPath}";
process.StartInfo.Arguments = $"msbuild /t:GenerateAspireManifest /p:AspireManifestPublishOutputPath={manifestPath}";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
Expand All @@ -26,12 +41,13 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
process.Start();
process.WaitForExit();

// TODO: Need better error handling, issue #3
if (process.ExitCode != 0)
{
Debug.WriteLine($"Error: {process.ExitCode}");
return;
}

await VS.Documents.OpenAsync(tempPath);
await VS.Documents.OpenAsync(manifestPath);
}
}
25 changes: 25 additions & 0 deletions src/Options/General.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace AspireManifestGen.Options;

internal partial class OptionsProvider
{
[ComVisible(true)]
public class GeneralOptions : BaseOptionPage<General> { }
}

public class General : BaseOptionModel<General>
{
[Category("Manifest file")]
[DisplayName("Default file name")]
[Description("The default name of the manifest file to be generated")]
[DefaultValue("aspire-manifest.json")]
public string DefaultName { get; set; } = "aspire-manifest.json";

[Category("Manifest file")]
[DisplayName("Use temporary file")]
[Description("Use a temporary file on disk instead of project location")]
[DefaultValue(true)]
public bool UseTempFile { get; set; } = true;
}

0 comments on commit f513ef0

Please sign in to comment.