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

Emit warning for projects detected in multiple drives #549

Merged
merged 2 commits into from
Nov 16, 2023

Conversation

mruxmohan4
Copy link
Contributor

@mruxmohan4 mruxmohan4 commented Nov 14, 2023

Use absolute instead of relative paths when the folder in a solution file is on a different drive from the root solution path and emit warning, as discussed in #512.

@mruxmohan4
Copy link
Contributor Author

mruxmohan4 commented Nov 14, 2023

Output after reproducing the issue locally post-fix:

Build started 11/15/2023 4:11:51 PM.
Generating solution for project "Q:\ProjectB\ProjectB.vcxitems"
Generating solution for project "C:\src\test\slngen-vcxitems\ProjectA\ProjectA.vcxitems"
Loading project references...
Loaded 2 project(s) in 173ms
Generating Visual Studio solution "Q:\ProjectB\Test.sln" ...
Updating existing solution file and reusing Visual Studio cache
SlnGen : warning : Detected folder on a different drive from the root solution path Q:\ProjectB\Test.sln. This folder should not be committed to source control since it does not contain a simple, relative path and is not guaranteed to work across machines.
Launching Visual Studio...

Success

SlnGen : warning : Detected folder on a different drive from the root solution path Q:\ProjectB\Test.sln. This folder should not be committed to source control since it does not contain a simple, relative path and is not guaranteed to work across machines.
    1 Warning(s)
    0 Error(s)

@mruxmohan4 mruxmohan4 force-pushed the dev/mruxmohan/sln-drive-fix branch 2 times, most recently from 7aef943 to 4d0af15 Compare November 14, 2023 22:07
@mruxmohan4 mruxmohan4 force-pushed the dev/mruxmohan/sln-drive-fix branch from 4d0af15 to f28434f Compare November 14, 2023 23:54
drives.Add(pathRoot);
}
}

string solutionPath = project.FullPath.ToRelativePath(rootPath).ToSolutionPath();
Copy link
Contributor Author

@mruxmohan4 mruxmohan4 Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffkl - Should multiple drives be detected before this section as well (as in, should this solution path, which is written to the stream, use absolute paths)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think detecting multiple drives is the right thing to do. Instead, if the drive that the current project is different from the drive that the solution file is being saved to, we need to use rooted absolute paths for that project's entry. If the project is on the same drive, the path should be relative. If one or more projects are on a different drive, then emit the warning. Does that sound right to you?

Copy link
Contributor Author

@mruxmohan4 mruxmohan4 Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a condition to detect whether the current project's drive is different from that of the solution file to ensure absolute paths are used if that differs, but I still needed to include the hasFullPath check since that led to the ArgumentException (the hierarchy includes a topmost-level folder that has "" for its absolute path).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest test output:

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProjectA", "C:\src\test\slngen-vcxitems\ProjectA\ProjectA.vcxitems", "{369B6908-BF24-4C02-8BB0-4139FD699D1D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProjectB", "ProjectB.vcxitems", "{905547D1-E9AF-4D80-8F83-2751E83D4557}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ProjectA", "C:\src\test\slngen-vcxitems\ProjectA", "{18234187-1FD6-4D2F-A26A-F9FC5FD67E9E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "slngen-vcxitems", "C:\src\test\slngen-vcxitems", "{048D148C-0E53-4770-A80E-40E40B181400}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "C:\src\test", "{59CC9E02-BE3C-4BCD-96A1-3243B7D7036F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "C:\src", "{D275FB7E-3968-465B-9679-3E738EB5E583}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ProjectB", "..\ProjectB", "{642B108B-866B-4B78-AD36-FAF88B6ECD4E}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|x64 = Debug|x64
		Release|x64 = Release|x64
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(NestedProjects) = preSolution
		{369B6908-BF24-4C02-8BB0-4139FD699D1D} = {18234187-1FD6-4D2F-A26A-F9FC5FD67E9E}
		{18234187-1FD6-4D2F-A26A-F9FC5FD67E9E} = {048D148C-0E53-4770-A80E-40E40B181400}
		{048D148C-0E53-4770-A80E-40E40B181400} = {59CC9E02-BE3C-4BCD-96A1-3243B7D7036F}
		{59CC9E02-BE3C-4BCD-96A1-3243B7D7036F} = {D275FB7E-3968-465B-9679-3E738EB5E583}
		{D275FB7E-3968-465B-9679-3E738EB5E583} = {BBAA5F6C-FCF6-4088-8AB6-C7650C6BE6AB}
		{905547D1-E9AF-4D80-8F83-2751E83D4557} = {642B108B-866B-4B78-AD36-FAF88B6ECD4E}
		{642B108B-866B-4B78-AD36-FAF88B6ECD4E} = {F8F3097E-FE30-46C8-B7CD-C73AEFE68DCE}
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {D0FD770F-48DF-419B-9E83-07C49EEFFD41}
	EndGlobalSection
	GlobalSection(SharedMSBuildProjectFiles) = preSolution
	EndGlobalSection
EndGlobal

@mruxmohan4 mruxmohan4 force-pushed the dev/mruxmohan/sln-drive-fix branch from 93e2a06 to e58a8bb Compare November 15, 2023 23:22
Copy link
Collaborator

@jeffkl jeffkl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mruxmohan4 mruxmohan4 force-pushed the dev/mruxmohan/sln-drive-fix branch from e58a8bb to 3085741 Compare November 16, 2023 00:12
@mruxmohan4 mruxmohan4 merged commit 6cd5b1d into microsoft:main Nov 16, 2023
5 checks passed
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

Successfully merging this pull request may close these issues.

2 participants