NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

dotnet restore: Ambiguous project name #12138

Open benvillalobos opened 2 years ago

benvillalobos commented 2 years ago

Issue moved from dotnet/msbuild#8026


From @codingdave on Thursday, October 6, 2022 6:55:06 AM

Issue Description

I have an application that I want to brand by overwriting the AssemblyName. Now if the .exe gets the same name as a dll msbuild restore will fail with:

dotnet restore
  Determining projects to restore...
C:\Program Files\dotnet\sdk\6.0.401\NuGet.targets(132,5): error : Ambiguous project name 'b'. 

Steps to Reproduce

Expected Behavior

My usecase is that I want to extend my application a.exe with the functionality of a plugin b.dll and brand the application as b.exe.

This will be the directory structure

b.exe
Plugins/b/b.dll

So the binaries will not get in their way

Actual Behavior

The error mentioned above

Analysis

The MsBuild RestoreTask seems to not take into account the extension, just the assemblyname. So it believes there is an ambiguity of b.exe and b.dll but they are differentiable by extension.

Versions & Configurations

dotnet --version 6.0.401

I only use dotnet build from non-developer powershell. But for completeness this is the msbuild version extracted from the developer console from VS 2022 (Version 17.3.0) msbuild -version MSBuild version 17.3.0+f67e3d35e for .NET Framework 17.3.0.37102

ghost commented 2 years ago

Issue is missing Type label, remember to add a Type label

erdembayar commented 2 years ago

I can repro this one, it looks exception is coming from below code: https://github.com/NuGet/NuGet.Client/blob/3ed642746f2609c6f586d096803630095b4add78/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs#L1181-L1185

image

image

ghost commented 2 years ago

Issue is missing Type label, remember to add a Type label

nkolev92 commented 2 years ago

Team Triage: You can workaround the issue by specifying PackageId.

When determining a project name, NuGet uses the following in order of preference, PackageId, AssemblyName, MSBuildProjectName. By setting PackageId, you'd prevent NuGet from having a.csproj have the name b.

We've had a lot of these issues filled in the past, and as such as we should consider documenting it. https://github.com/NuGet/Home/issues?q=is%3Aissue+Ambiguous+project+name+is%3Aclosed.

Marking this as a docs issue.