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

Debug launch profiles UI - Roslyn Component - crashes if there is a space in the output directory path. #1206

Open
sjb-sjb opened this issue Jan 19, 2025 · 1 comment
Assignees

Comments

@sjb-sjb
Copy link

sjb-sjb commented Jan 19, 2025

Visual Studio Version

17.12.4

Summary

If there is a space in the BaseOutputPath and BaseIntermediateOutputPath then creating a Roslyn Component launch profile using "Open debug launch profiles UI" causes a crash.

Steps to Reproduce

  1. Create a .NET standard 2.0 class library with the following .csproj:
    <Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<TargetFramework>netstandard2.0</TargetFramework>
		<IsRoslynComponent>true</IsRoslynComponent>
		<IncludeBuildOutput>true</IncludeBuildOutput>
		<Nullable>enable</Nullable>
		<LangVersion>latest</LangVersion>
		<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
		<RootNamespace>Q5.Framework.Generator</RootNamespace>
	</PropertyGroup>

	<ItemGroup>
		<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
			<PrivateAssets>all</PrivateAssets>
			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
		</PackageReference>
		<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
	</ItemGroup>
    </Project>
  1. Add the following Directory.Build.props and change xxxx to your user name and yyyy to your project name (with no blanks):
    <Project>
	<PropertyGroup>
		<BaseOutputPath>C:\Users\xxxx\Documents\VS-Output\yyyy</BaseOutputPath>
		<BaseIntermediateOutputPath>C:\Users\xxxx\Documents\VS-Output\yyyy</BaseIntermediateOutputPath>
		<EnforceExtendedAnalyserRules>true</EnforceExtendedAnalyserRules>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\Generated</CompilerGeneratedFilesOutputPath>
		
		<Nullable>enable</Nullable>

		<CsWinRTAotOptimizerEnabled>false</CsWinRTAotOptimizerEnabled>
		<CsWinRTRcwFactoryFallbackGeneratorForceOptOut>true</CsWinRTRcwFactoryFallbackGeneratorForceOptOut>
	</PropertyGroup>
    </Project>
 
  1. Right-click on the project, select Properties > General > Open debug launch profiles UI. It works. Now go back and remove the "-" in "VS-Output" and do it again. Create a Roslyn Component profile. It crashes.

Expected Behavior

Should be able to create a Roslyn Component profile when there is a space in the path.

Actual Behavior

It crashes with an exception saying invalid character.

User Impact

Lost a lot of time figuring this one out!!

@LittleLittleCloud
Copy link

LittleLittleCloud commented Jan 27, 2025

The cause for this issue is because the path will be quoted (wrapped within ") when it contains space when passing as targetArgs. Therefore it raises an ArgumentException in Path.GetFileName because " is an illegal character.

To illustrate with an example, given the path to be C:\Users\xxxx\Documents\VS-Output\yy yy (with a space), it will turn to be /out: \"C:\\Users\\xxxx\\Documents\\VS-Output\\yy yy\" in targetArgs, and fail the internal path check inside Path.GetFileName

Proposed Fix:

properly process the path when it's quoted in GetComponentReferencingProjectsAsync

@drewnoakes drewnoakes transferred this issue from dotnet/project-system Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants