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

switcher - support for duplicated project names #116

Open
Leon99 opened this issue Sep 2, 2022 · 2 comments
Open

switcher - support for duplicated project names #116

Leon99 opened this issue Sep 2, 2022 · 2 comments

Comments

@Leon99
Copy link

Leon99 commented Sep 2, 2022

Let's say we have a solution SA with project PA that builds package SA.PA, and solution SB with projects PA and PB. Project PB uses a package SA.PA. Running switch-to-projects on SB throws an exception in this case. PA (from SA) is actually added to SB after that but the PackageReference to SA.PA in PB is not replaced.

Exception:

Microsoft.Build.Exceptions.InvalidProjectFileException: The solution file has two projects named "PA".  ...\SB\SB.sln
   at Microsoft.Build.Shared.ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(Boolean condition, String errorSubCategoryResourceName, BuildEventFileInfo projectFile, Exception innerException, String resourceName, Object[] args)
   at Microsoft.Build.Construction.SolutionFile.ParseSolution()
   at Microsoft.Build.Construction.SolutionFile.ParseSolutionFile()
   at Microsoft.Build.Construction.SolutionFile.Parse(String solutionFile)
   at Dnt.Commands.Packages.SwitchPackagesToProjectsCommand.SwitchToProjects(ReferenceSwitcherConfiguration configuration, IConsoleHost host) in C:\projects\dnt\src\Dnt.Commands\Packages\SwitchPackagesToProjectsCommand.cs:line 0
   at Dnt.Commands.Packages.SwitchPackagesToProjectsCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in C:\projects\dnt\src\Dnt.Commands\Packages\SwitchPackagesToProjectsCommand.cs:line 29
   at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
   at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
   at NConsole.CommandLineProcessor.Process(String[] args, Object input)
   at Dnt.Program.Main(String[] args) in C:\projects\dnt\src\Dnt\Program.cs:line 33

We have hundreds of solutions and, sadly, most of them ignore MS guidelines and have projects with the same name.

@RicoSuter I'd be happy to fix it myself if you point me in the right direction. Thanks!

@ssteiner
Copy link

I don't think you can fix that.. the exception comes from the Microsoft.Build namespace (which are dependencies of dnt) - if at all you'd have to talk to the guys in charge of the MSBuild tools. The alternative would be to write your own sln parser and replace the usage of the MSBuild sln parser. You'd start with using (var projectInformation = ProjectExtensions.LoadProject(solutionProject.AbsolutePath, globalProperties)) in SwitchPackagesToProjectsCommand . But you'd probably spend quite a bit of time ripping everything out.

Though, how do you get your dev environment to even load an .sln that MS considers invalid? I guess I'm not getting how your projects look. Switching the solution SA would work, right?
When you switch SB, your switcher file would say to replace package SA.PA with project PA. If PA is already in the SB.SLN, it shouldn't be re-added - so after the switch SB.SLN should contain PA and PB, no?

@tripleacoder
Copy link

I have this problem too, where an app called "DefectEditor" references a Nuget project named "DefectEditor".

switch-to-prjects does not work in this case.

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

3 participants