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

Import support for IIS Express #17

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,7 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

# Resharper and Rider settings
.idea/
7 changes: 7 additions & 0 deletions Aspirant.sln
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspirant.Hosting.PostgreSQL
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspirant.Hosting.RabbitMQ", "src\Aspirant.Hosting.RabbitMQ\Aspirant.Hosting.RabbitMQ.csproj", "{45EC9DE1-B3E7-4EF4-A0AA-8CD7230EB7FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspirant.Hosting.IISExpress", "src\Aspirant.Hosting.IISExpress\Aspirant.Hosting.IISExpress.csproj", "{A66C0A1E-B3F4-4C66-8873-024F09DB4002}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -110,6 +112,10 @@ Global
{45EC9DE1-B3E7-4EF4-A0AA-8CD7230EB7FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45EC9DE1-B3E7-4EF4-A0AA-8CD7230EB7FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45EC9DE1-B3E7-4EF4-A0AA-8CD7230EB7FB}.Release|Any CPU.Build.0 = Release|Any CPU
{A66C0A1E-B3F4-4C66-8873-024F09DB4002}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A66C0A1E-B3F4-4C66-8873-024F09DB4002}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A66C0A1E-B3F4-4C66-8873-024F09DB4002}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A66C0A1E-B3F4-4C66-8873-024F09DB4002}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -130,6 +136,7 @@ Global
{135004A9-F7E0-46D9-B3D0-3D64BA3C40B9} = {6E773CFD-9758-4C09-96F6-5EDCED0E3A34}
{77D17495-C537-4446-8C2E-8B46560E0992} = {6E773CFD-9758-4C09-96F6-5EDCED0E3A34}
{45EC9DE1-B3E7-4EF4-A0AA-8CD7230EB7FB} = {6E773CFD-9758-4C09-96F6-5EDCED0E3A34}
{A66C0A1E-B3F4-4C66-8873-024F09DB4002} = {6E773CFD-9758-4C09-96F6-5EDCED0E3A34}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {52627286-38AF-4E95-BDA0-B21166B2B18C}
Expand Down
16 changes: 16 additions & 0 deletions src/Aspirant.Hosting.IISExpress/Aspirant.Hosting.IISExpress.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Description>A set of useful extensions and experiments for IIS Express for .NET Aspire App Host projects.</Description>
<PackageTags>aspire hosting rabbitmq</PackageTags>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Aspirant.Hosting\Aspirant.Hosting.csproj" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/Aspirant.Hosting.IISExpress/IISExpressResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Aspire.Hosting;
using Aspire.Hosting.ApplicationModel;
// ReSharper disable InconsistentNaming
// ReSharper disable CheckNamespace

namespace Aspirant.Hosting;

/// <summary>
/// Represents a IIS Express resource.
/// </summary>
/// <param name="name">The name of the resource in the application model.</param>
/// <param name="path">The path to the IIS Express executable.</param>
/// <param name="workingDirectory">The working directory of the executable.</param>
public class IISExpressResource(string name, string path, string workingDirectory = ".")
: ExecutableResource(name, path, workingDirectory), IResourceWithServiceDiscovery
{

}
40 changes: 40 additions & 0 deletions src/Aspirant.Hosting.IISExpress/IISExpressResourceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Aspire.Hosting;
using Aspire.Hosting.ApplicationModel;
// ReSharper disable InconsistentNaming
// ReSharper disable CheckNamespace

namespace Aspirant.Hosting;

/// <summary>
/// Extensions for the <see cref="IISExpressResource"/>
/// </summary>
public static class IISExpressResourceExtensions
{
/// <summary>
///
/// </summary>
/// <param name="builder">The builder.</param>
/// <param name="name">The name of the resource.</param>
/// <param name="applicationPath">The path to the web application to host in IIS Express.</param>
/// <param name="arch">The architecture of IIS Express to be used.</param>

Check warning on line 19 in src/Aspirant.Hosting.IISExpress/IISExpressResourceExtensions.cs

View workflow job for this annotation

GitHub Actions / Build & Test PR / Build & Test

XML comment has a param tag for 'arch', but there is no parameter by that name

Check warning on line 19 in src/Aspirant.Hosting.IISExpress/IISExpressResourceExtensions.cs

View workflow job for this annotation

GitHub Actions / Build & Test PR / Build & Test

XML comment has a param tag for 'arch', but there is no parameter by that name
/// <returns>The builder.</returns>
public static IResourceBuilder<IISExpressResource> AddIISExpress(this IDistributedApplicationBuilder builder, string name, string applicationPath)
{
var iisExpressPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "IIS Express", "iisexpress.exe");

var appPath = Path.GetFullPath(applicationPath, builder.AppHostDirectory);

var resource = new IISExpressResource(name, iisExpressPath);

return builder.AddResource(resource)
.WithArgs($"/path:{appPath}", "/systray:false")
.WithArgs(context =>
{
var http = resource.GetEndpoint("http");

var portExpression = ReferenceExpression.Create($"/port:{http.Property(EndpointProperty.TargetPort)}");
context.Args.Add(portExpression);
})
.WithHttpEndpoint(name: "http");
}
}