Describe the bug
AddIISExpressProject from Aspire.Hosting.IncrementalMigration will throw an InvalidOperationException ("Sequence contains more than one element") if the referenced ASP.NET project itself contains project reference (which would be all but the most simple sites) and a launchProfile.json doesn't exist (i.e. reading from the old-style csproj itself).
In IISExpressLaunchDetailsExtensions.TryParseOldStyleProjects, after the csproj is loaded as an xml document, an attempt to grab the root <Project> is made (doc.Descendants(MsbuildNS + "Project").SingleOrDefault()). However Descendants grabs all <Project> nodes, which includes those that are children of <ProjectReference>, which trips the SingleOrDefault.
To Reproduce
Create a class library project and add it as a project reference to the ASP.NET Framework project referenced by the Aspire AppHost.
This repo+branch also reproduced the issue:
https://github.com/Sebbs128/AspireNetFramework/tree/update-to-swa-hosting-package
Exceptions (if any)
System.InvalidOperationException 'Sequence contains more than one element'
Stacktrace
at System.Linq.ThrowHelper.ThrowMoreThanOneElementException()
at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Boolean& found)
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at Aspire.Hosting.IISExpressLaunchDetailsExtensions.TryParseOldStyleProject(String path, IISExpressLaunchDetails& metadata)
at Aspire.Hosting.IISExpressLaunchDetailsExtensions.GetLaunchDetails(IProjectMetadata metadata)
at Aspire.Hosting.IISExpressProjectExtensions.AddIISExpressProject[TProject](IDistributedApplicationBuilder builder, String name)
at Program.<Main>$(String[] args) in D:\\source\\AspireNetFramework\\samples\\AspireNetFramework.Samples.AppHost\\Program.cs:line 9
Further technical details
Please include the following if applicable:
ASP.NET Framework Application:
- Technologies and versions used (i.e. MVC/WebForms/etc): MVC
- .NET Framework Version: 4.8
- IIS Version: IISExpress 10.0.26013.1000
- Windows Version: Windows 11 (100.22621)
ASP.NET Core Application:
- Targeted .NET version: 10
- .NET SDK version: 10.0.300
Describe the bug
AddIISExpressProjectfrom Aspire.Hosting.IncrementalMigration will throw anInvalidOperationException("Sequence contains more than one element") if the referenced ASP.NET project itself contains project reference (which would be all but the most simple sites) and a launchProfile.json doesn't exist (i.e. reading from the old-style csproj itself).In
IISExpressLaunchDetailsExtensions.TryParseOldStyleProjects, after the csproj is loaded as an xml document, an attempt to grab the root<Project>is made (doc.Descendants(MsbuildNS + "Project").SingleOrDefault()). HoweverDescendantsgrabs all<Project>nodes, which includes those that are children of<ProjectReference>, which trips theSingleOrDefault.To Reproduce
Create a class library project and add it as a project reference to the ASP.NET Framework project referenced by the Aspire AppHost.
This repo+branch also reproduced the issue:
https://github.com/Sebbs128/AspireNetFramework/tree/update-to-swa-hosting-package
Exceptions (if any)
System.InvalidOperationException 'Sequence contains more than one element'
Stacktrace
Further technical details
Please include the following if applicable:
ASP.NET Framework Application:
ASP.NET Core Application: