Skip to content

add --create-manifest-if-needed flag #31231

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

Merged
merged 16 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Cli/Microsoft.DotNet.Cli.Utils/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ public static class Constants
public const string DefaultConfiguration = "Debug";

public static readonly string ProjectFileName = "project.json";
public static readonly string ManifestFileName = "dotnet-tools.json";
public static readonly string DotConfigDirectoryName = ".config";
public static readonly string ExeSuffix =
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty;

public static readonly string BinDirectoryName = "bin";
public static readonly string ObjDirectoryName = "obj";
public static readonly string GitDirectoryName = ".git";

public static readonly string MSBUILD_EXE_PATH = "MSBUILD_EXE_PATH";
public static readonly string MSBuildExtensionsPath = "MSBuildExtensionsPath";
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/ToolManifest/IToolManifestFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.DotNet.ToolManifest
internal interface IToolManifestFinder
{
IReadOnlyCollection<ToolManifestPackage> Find(FilePath? filePath = null);
FilePath FindFirst();
FilePath FindFirst(bool createManifestFileOption = false);
IReadOnlyList<FilePath> FindByPackageId(PackageId packageId);
}
}
9 changes: 8 additions & 1 deletion src/Cli/dotnet/ToolManifest/LocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,11 @@ For a list of locations searched, specify the "-d" option before the tool name.<
<data name="MultipleSamePackageId" xml:space="preserve">
<value>More than one entry exists for package(s): {0}.</value>
</data>
</root>
<data name="ManifestFileContent" xml:space="preserve">
<value>{
"version": 1,
"isRoot": true,
"tools": {}
}</value>
</data>
</root>
50 changes: 44 additions & 6 deletions src/Cli/dotnet/ToolManifest/ToolManifestFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ToolPackage;
using Microsoft.Extensions.EnvironmentAbstractions;
using NuGet.Packaging;

namespace Microsoft.DotNet.ToolManifest
{
Expand Down Expand Up @@ -153,7 +155,7 @@ public bool TryFind(ToolCommandName toolCommandName, out ToolManifestPackage too
}
}

public FilePath FindFirst()
public FilePath FindFirst(bool createManifestFileOption = false)
{
foreach ((FilePath possibleManifest, DirectoryPath _) in EnumerateDefaultAllPossibleManifests())
{
Expand All @@ -162,12 +164,48 @@ public FilePath FindFirst()
return possibleManifest;
}
}

if (createManifestFileOption)
{
DirectoryPath manifestInsertFolder = GetInsertManifestFilePath();
if (manifestInsertFolder.Value != null)
{
return new FilePath(WriteManifestFile(manifestInsertFolder));
}
}
throw new ToolManifestCannotBeFoundException(
LocalizableStrings.CannotFindAManifestFile,
string.Format(LocalizableStrings.ListOfSearched,
string.Join(Environment.NewLine,
EnumerateDefaultAllPossibleManifests().Select(f => "\t" + f.manifestfile.Value))));
LocalizableStrings.CannotFindAManifestFile,
string.Format(LocalizableStrings.ListOfSearched,
string.Join(Environment.NewLine,
EnumerateDefaultAllPossibleManifests().Select(f => "\t" + f.manifestfile.Value))));
}

private DirectoryPath GetInsertManifestFilePath()
{
DirectoryPath? currentSearchDirectory = _probeStart;
while (currentSearchDirectory.HasValue)
{
var currentSearchGitDirectory = currentSearchDirectory.Value.WithSubDirectories(Constants.GitDirectoryName);
if (Directory.Exists(currentSearchGitDirectory.Value))
{
return currentSearchDirectory.Value;
}
if (Directory.GetFiles(currentSearchDirectory.Value.Value, "*.sln").Any() || Directory.GetFiles(currentSearchDirectory.Value.Value, "*.git").Any())
{
return currentSearchDirectory.Value;
}
currentSearchDirectory = currentSearchDirectory.Value.GetParentPathNullable();
}
return _probeStart;
}

private string WriteManifestFile(DirectoryPath folderPath)
{
var manifestFileContent = LocalizableStrings.ManifestFileContent;
Directory.CreateDirectory(folderPath.Value + "/" + Constants.DotConfigDirectoryName);
string manifestFileLocation = folderPath.Value + "/" + Constants.DotConfigDirectoryName + "/" + Constants.ManifestFileName;
File.WriteAllText(manifestFileLocation, manifestFileContent);

return manifestFileLocation;
}

/// <summary>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ Pokud si chcete zobrazit seznam prohledaných umístění, zadejte před název
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">Soubor {0} pochází z jiného počítače a je možné, že se zablokoval, aby se ochránil tento počítač. Další informace včetně toho, jak soubor odblokovat, najdete na adrese https://aka.ms/motw.</target>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ Eine Liste der durchsuchten Speicherorte erhalten Sie, indem Sie vor dem Toolnam
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">Die Datei "{0}" stammt von einem anderen Computer und wurde möglicherweise zum Schutz dieses Computers blockiert. Weitere Informationen zum Aufheben der Sperre und zu anderen Aktionen finden Sie unter https://aka.ms/motw.</target>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ Para obtener una lista de ubicaciones buscadas, especifique la opción "-d" dela
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">El archivo {0} procedía de otro equipo y podría bloquearse para ayudar a proteger este equipo. Para obtener más información, y cómo desbloquearlo, consulte https://aka.ms/motw</target>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ Pour obtenir une liste des emplacements de recherche, spécifiez l'option "-d" a
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">Le fichier {0} provient d'un autre ordinateur et a éventuellement été bloqué pour protéger cet ordinateur. Pour plus d'informations, notamment sur le déblocage, consultez https://aka.ms/motw</target>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ Per un elenco dei percorso di ricerca, specificare l'opzione "-d" prima del nome
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">Il file {0} proviene da un altro computer e potrebbe essere stato bloccato per proteggere questo computer. Per altre informazioni, incluse le istruzioni su come sbloccare il file, vedere https://aka.ms/motw</target>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ For a list of locations searched, specify the "-d" option before the tool name.<
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">ファイル {0} は別のコンピューターからのもので、このコンピューターを保護するためにブロックされている可能性があります。ブロックを解除する方法を含む詳細については、https://aka.ms/motw を参照してください</target>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ For a list of locations searched, specify the "-d" option before the tool name.<
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">{0} 파일은 다른 컴퓨터에서 제공되었으며 이 컴퓨터를 보호하기 위해 차단되었을 수 있습니다. 차단 해제 방법을 비롯한 자세한 내용은 https://aka.ms/motw를 참조하세요.</target>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ Aby uzyskać listę przeszukiwanych lokalizacji, określ opcję „-d” przed n
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">Plik {0} pochodzi z innego komputera i może zostać zablokowany, aby pomóc chronić ten komputer. Aby uzyskać więcej informacji, w tym o sposobie odblokowywania, zobacz https://aka.ms/motw</target>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ Para obter uma lista de localizações pesquisadas, especifique a opção "-d" a
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">O arquivo {0} veio de outro computador e pode estar bloqueado para ajudar a proteger este computador. Para obter mais informações, incluindo como desbloquear, consulte https://aka.ms/motw</target>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ For a list of locations searched, specify the "-d" option before the tool name.<
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">Файл {0} получен с другого компьютера и может быть заблокирован для защиты этого компьютера. Дополнительные сведения, включая процедуру разблокировки, см. на странице https://aka.ms/motw</target>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ Aranan konumların bir listesi için aracın adından önce "-d" seçeneğini be
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">{0} adlı dosya başka bir bilgisayardan geldiğinden bilgisayarı korumaya yardımcı olmak için engellenmiş olabilir. Engellemenin nasıl kaldırılacağı da dahil olmak üzere daha fazla bilgi için bkz. https://aka.ms/motw</target>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ For a list of locations searched, specify the "-d" option before the tool name.<
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">文件 {0} 来自另一台计算机,而且可能会被阻止以帮助保护此计算机。有关详细信息(包括如何解除阻止),请参阅 https://aka.ms/motw</target>
Expand Down
13 changes: 13 additions & 0 deletions src/Cli/dotnet/ToolManifest/xlf/LocalizableStrings.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ For a list of locations searched, specify the "-d" option before the tool name.<
{0}</target>
<note />
</trans-unit>
<trans-unit id="ManifestFileContent">
<source>{
"version": 1,
"isRoot": true,
"tools": {}
}</source>
<target state="new">{
"version": 1,
"isRoot": true,
"tools": {}
}</target>
<note />
</trans-unit>
<trans-unit id="ManifestHasMarkOfTheWeb">
<source>File {0} came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw</source>
<target state="translated">檔案 {0} 來自另一部電腦,但此電腦可能已封鎖而加以保護。如需詳細資訊,包括如何解除封鎖,請參閱 https://aka.ms/motw</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,10 @@ If you would like to create a manifest, use `dotnet new tool-manifest`, usually
<data name="PrereleaseAndVersionAreNotSupportedAtTheSameTime" xml:space="preserve">
<value>The --prerelease and --version options are not supported in the same command</value>
</data>
<data name="CreateManifestIfNeededOptionDescription" xml:space="preserve">
<value>Create tool manifest when installing tools if manifest not exist.</value>
</data>
<data name="CreateManifestIfNeededOptionName" xml:space="preserve">
<value>MANIFEST</value>
</data>
</root>
Loading