diff --git a/src/Cli/dotnet/CliStrings.resx b/src/Cli/dotnet/CliStrings.resx index 3f000e269cd8..ea37a0b0333e 100644 --- a/src/Cli/dotnet/CliStrings.resx +++ b/src/Cli/dotnet/CliStrings.resx @@ -252,6 +252,9 @@ Solution {0} already contains project {1}. + + Solution folder '{0}' already contains a project with the filename '{1}'. + You must specify at least one reference to remove. diff --git a/src/Cli/dotnet/Commands/Solution/Add/SolutionAddCommand.cs b/src/Cli/dotnet/Commands/Solution/Add/SolutionAddCommand.cs index 338271e6c8cf..6e86dea43214 100644 --- a/src/Cli/dotnet/Commands/Solution/Add/SolutionAddCommand.cs +++ b/src/Cli/dotnet/Commands/Solution/Add/SolutionAddCommand.cs @@ -165,6 +165,37 @@ private void AddProject(SolutionModel solution, string fullProjectPath, ISolutio // Generate the solution folder path based on the project path SolutionFolderModel? solutionFolder = GenerateIntermediateSolutionFoldersForProjectPath(solution, solutionRelativeProjectPath); + // Check if a project with the same filename already exists in the solution folder + string projectFileName = Path.GetFileName(solutionRelativeProjectPath); + if (solutionFolder != null) + { + var rootFolder = solutionFolder; + while (rootFolder.Parent is SolutionFolderModel parentFolder) + { + rootFolder = parentFolder; + } + + var existingProjectWithSameName = solution.SolutionProjects.FirstOrDefault( + p => IsInSameFolderHierarchy(p.Parent, rootFolder) && Path.GetFileName(p.FilePath).Equals(projectFileName, StringComparison.OrdinalIgnoreCase)); + + if (existingProjectWithSameName != null) + { + throw new GracefulException(string.Format(CliStrings.SolutionFolderAlreadyContainsProjectWithFilename, rootFolder.Name, projectFileName)); + } + } + + static bool IsInSameFolderHierarchy(SolutionItemModel? projectParent, SolutionFolderModel rootFolder) + { + var current = projectParent; + while (current != null) + { + if (current == rootFolder) + return true; + current = current.Parent; + } + return false; + } + SolutionProjectModel project; try diff --git a/src/Cli/dotnet/xlf/CliStrings.cs.xlf b/src/Cli/dotnet/xlf/CliStrings.cs.xlf index 9281b2b60519..bc8118692866 100644 --- a/src/Cli/dotnet/xlf/CliStrings.cs.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.cs.xlf @@ -1029,6 +1029,11 @@ Výchozí hodnota je false. Pokud však cílíte na .NET 7 nebo nižší a je za Zadaný soubor řešení {0} neexistuje nebo v adresáři není soubor řešení. + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. Soubor projektu nebo řešení, se kterým se má operace provést. Pokud soubor není zadaný, příkaz ho bude hledat v aktuálním adresáři. diff --git a/src/Cli/dotnet/xlf/CliStrings.de.xlf b/src/Cli/dotnet/xlf/CliStrings.de.xlf index 06e36432caa8..6157c0b591d4 100644 --- a/src/Cli/dotnet/xlf/CliStrings.de.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.de.xlf @@ -1029,6 +1029,11 @@ Der Standardwert lautet FALSE. Wenn sie jedoch auf .NET 7 oder niedriger abziele Die angegebene Projektmappendatei "{0}" ist nicht vorhanden, oder das Verzeichnis enthält keine Projektmappendatei. + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. Das Projekt oder die Projektmappendatei, die verwendet werden soll. Wenn keine Datei angegeben ist, durchsucht der Befehl das aktuelle Verzeichnis nach einer Datei. diff --git a/src/Cli/dotnet/xlf/CliStrings.es.xlf b/src/Cli/dotnet/xlf/CliStrings.es.xlf index 958ecc950691..932f14aad0a5 100644 --- a/src/Cli/dotnet/xlf/CliStrings.es.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.es.xlf @@ -1029,6 +1029,11 @@ El valor predeterminado es "false." Sin embargo, cuando el destino es .NET 7 o i El archivo de solución {0} especificado no existe, o bien no hay ningún archivo de solución en el directorio. + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. El archivo de proyecto o solución donde operar. Si no se especifica un archivo, el comando buscará uno en el directorio actual. diff --git a/src/Cli/dotnet/xlf/CliStrings.fr.xlf b/src/Cli/dotnet/xlf/CliStrings.fr.xlf index 5db31a60a949..c52c236d5ae4 100644 --- a/src/Cli/dotnet/xlf/CliStrings.fr.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.fr.xlf @@ -1029,6 +1029,11 @@ La valeur par défaut est « false ». Toutefois, lorsque vous ciblez .NET 7 o Le fichier solution spécifié {0} n'existe pas ou il n'y a pas de fichier solution dans le répertoire. + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. Fichier projet ou solution à utiliser. Si vous ne spécifiez pas de fichier, la commande en recherche un dans le répertoire actuel. diff --git a/src/Cli/dotnet/xlf/CliStrings.it.xlf b/src/Cli/dotnet/xlf/CliStrings.it.xlf index e0ab4a991a6d..7e1e970856f4 100644 --- a/src/Cli/dotnet/xlf/CliStrings.it.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.it.xlf @@ -1029,6 +1029,11 @@ Il valore predefinito è 'false'. Tuttavia, quando la destinazione è .NET 7 o u Il file di soluzione specificato {0} non esiste oppure nella directory non è presente alcun file di soluzione. + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. File di progetto o di soluzione su cui intervenire. Se non si specifica un file, il comando ne cercherà uno nella directory corrente. diff --git a/src/Cli/dotnet/xlf/CliStrings.ja.xlf b/src/Cli/dotnet/xlf/CliStrings.ja.xlf index 1c60e39eea21..3c65a24afdd1 100644 --- a/src/Cli/dotnet/xlf/CliStrings.ja.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.ja.xlf @@ -1029,6 +1029,11 @@ The default is 'false.' However, when targeting .NET 7 or lower, the default is 指定したソリューション ファイル {0} が存在しないか、ディレクトリにソリューション ファイルがありません。 + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. 利用するプロジェクト ファイルまたはソリューション ファイル。指定しない場合、コマンドは現在のディレクトリを検索します。 diff --git a/src/Cli/dotnet/xlf/CliStrings.ko.xlf b/src/Cli/dotnet/xlf/CliStrings.ko.xlf index 9b17fe1f2fe9..5e9908f47783 100644 --- a/src/Cli/dotnet/xlf/CliStrings.ko.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.ko.xlf @@ -1029,6 +1029,11 @@ The default is 'false.' However, when targeting .NET 7 or lower, the default is 지정한 솔루션 파일 {0}이(가) 없거나 디렉터리에 솔루션 파일이 없습니다. + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. 수행할 프로젝트 또는 솔루션 파일입니다. 파일을 지정하지 않으면 명령이 현재 디렉토리에서 파일을 검색합니다. diff --git a/src/Cli/dotnet/xlf/CliStrings.pl.xlf b/src/Cli/dotnet/xlf/CliStrings.pl.xlf index 76ccf8a90a4e..a0827e6cca19 100644 --- a/src/Cli/dotnet/xlf/CliStrings.pl.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.pl.xlf @@ -1029,6 +1029,11 @@ Wartość domyślna to „false”. Jednak w przypadku określania wartości doc Określony plik rozwiązania {0} nie istnieje bądź w katalogu nie ma żadnego pliku rozwiązania. + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. Plik projektu lub rozwiązania, dla którego ma zostać wykonana operacja. Jeśli plik nie zostanie podany, polecenie wyszuka go w bieżącym katalogu. diff --git a/src/Cli/dotnet/xlf/CliStrings.pt-BR.xlf b/src/Cli/dotnet/xlf/CliStrings.pt-BR.xlf index dd485568a4ca..1427fb9cae3c 100644 --- a/src/Cli/dotnet/xlf/CliStrings.pt-BR.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.pt-BR.xlf @@ -1029,6 +1029,11 @@ O padrão é 'false.' No entanto, ao direcionar para .NET 7 ou inferior, o padr O arquivo de solução {0} especificado não existe ou não há um arquivo de solução no diretório. + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. O arquivo de solução ou projeto para operar. Se um arquivo não for especificado, o comando pesquisará um no diretório atual. diff --git a/src/Cli/dotnet/xlf/CliStrings.ru.xlf b/src/Cli/dotnet/xlf/CliStrings.ru.xlf index d487cd169a11..16d9ce2ed2a1 100644 --- a/src/Cli/dotnet/xlf/CliStrings.ru.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.ru.xlf @@ -1029,6 +1029,11 @@ The default is 'false.' However, when targeting .NET 7 or lower, the default is Указанный файл решения "{0}" не существует, или в каталоге нет файла решения. + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. Файл проекта или решения. Если файл не указан, команда будет искать его в текущем каталоге. diff --git a/src/Cli/dotnet/xlf/CliStrings.tr.xlf b/src/Cli/dotnet/xlf/CliStrings.tr.xlf index 5a0d120babd0..4718e0657a61 100644 --- a/src/Cli/dotnet/xlf/CliStrings.tr.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.tr.xlf @@ -1029,6 +1029,11 @@ Varsayılan değer 'false.' Ancak çalışma zamanı tanımlayıcısı belirtild Belirtilen {0} çözüm dosyası yok veya dizinde bir çözüm dosyası yok. + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. Üzerinde işlem yapılacak proje veya çözüm dosyası. Bir dosya belirtilmezse komut geçerli dizinde dosya arar. diff --git a/src/Cli/dotnet/xlf/CliStrings.zh-Hans.xlf b/src/Cli/dotnet/xlf/CliStrings.zh-Hans.xlf index 5b6fc1256332..1276bb9fea39 100644 --- a/src/Cli/dotnet/xlf/CliStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.zh-Hans.xlf @@ -1029,6 +1029,11 @@ The default is 'false.' However, when targeting .NET 7 or lower, the default is 指定的解决方案文件 {0} 不存在,或目录中没有解决方案文件。 + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. 要操作的项目或解决方案文件。如果没有指定文件,则命令将在当前目录里搜索一个文件。 diff --git a/src/Cli/dotnet/xlf/CliStrings.zh-Hant.xlf b/src/Cli/dotnet/xlf/CliStrings.zh-Hant.xlf index 3df700ef997d..bd73674ba27c 100644 --- a/src/Cli/dotnet/xlf/CliStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.zh-Hant.xlf @@ -1029,6 +1029,11 @@ The default is 'false.' However, when targeting .NET 7 or lower, the default is 指定的方案檔 {0} 不存在,或目錄中沒有方案檔。 + + Solution folder '{0}' already contains a project with the filename '{1}'. + Solution folder '{0}' already contains a project with the filename '{1}'. + + The project or solution file to operate on. If a file is not specified, the command will search the current directory for one. 要操作的專案或解決方案。若未指定檔案,命令就會在目前的目錄中搜尋一個檔案。 diff --git a/test/dotnet.Tests/CommandTests/Solution/Add/GivenDotnetSlnAdd.cs b/test/dotnet.Tests/CommandTests/Solution/Add/GivenDotnetSlnAdd.cs index 3f78a0896e87..98fef585e52d 100644 --- a/test/dotnet.Tests/CommandTests/Solution/Add/GivenDotnetSlnAdd.cs +++ b/test/dotnet.Tests/CommandTests/Solution/Add/GivenDotnetSlnAdd.cs @@ -294,7 +294,7 @@ public void WhenNestedProjectIsAddedSolutionFoldersAreCreatedBuild(string soluti } - [Theory(Skip = "https://github.com/dotnet/sdk/issues/47859")] + [Theory] [InlineData("sln")] [InlineData("solution")] public void WhenNestedDuplicateProjectIsAddedToASolutionFolder(string solutionCommand)