Example #1
0
        private IReadOnlyList <RestoredCommand> GetCommands()
        {
            try
            {
                // The mock restorer wrote the path to the executable into project.assets.json (not a real assets file)
                // Currently only "dotnet" commands are supported
                var executablePath = _fileSystem.File.ReadAllText(Path.Combine(PackageDirectory.Value, "project.assets.json"));

                var fakeSettingFile = _fileSystem.File.ReadAllText(Path.Combine(PackageDirectory.Value, ProjectRestorerMock.FakeCommandSettingsFileName));

                string name;
                using (JsonDocument doc = JsonDocument.Parse(fakeSettingFile))
                {
                    JsonElement root = doc.RootElement;
                    name = root.GetProperty("Name").GetString();
                }

                return(new RestoredCommand[]
                {
                    new RestoredCommand(
                        new ToolCommandName(name),
                        "dotnet",
                        PackageDirectory.WithFile(executablePath))
                });
            }
            catch (IOException ex)
            {
                throw new ToolPackageException(
                          string.Format(
                              CommonLocalizableStrings.FailedToRetrieveToolConfiguration,
                              Id,
                              ex.Message),
                          ex);
            }
        }
Example #2
0
 private IReadOnlyList <RestoredCommand> GetCommands()
 {
     try
     {
         // The mock restorer wrote the path to the executable into project.assets.json (not a real assets file)
         // Currently only "dotnet" commands are supported
         var executablePath = _fileSystem.File.ReadAllText(Path.Combine(PackageDirectory.Value, "project.assets.json"));
         return(new RestoredCommand[]
         {
             new RestoredCommand(
                 ProjectRestorerMock.FakeCommandName,
                 "dotnet",
                 PackageDirectory.WithFile(executablePath))
         });
     }
     catch (IOException ex)
     {
         throw new ToolPackageException(
                   string.Format(
                       CommonLocalizableStrings.FailedToRetrieveToolConfiguration,
                       Id,
                       ex.Message),
                   ex);
     }
 }
Example #3
0
        private IReadOnlyList <CommandSettings> GetCommands()
        {
            const string AssetsFileName       = "project.assets.json";
            const string ToolSettingsFileName = "DotnetToolSettings.xml";

            try
            {
                var commands = new List <CommandSettings>();
                var lockFile = new LockFileFormat().Read(PackageDirectory.WithFile(AssetsFileName).Value);

                var library            = FindLibraryInLockFile(lockFile);
                var dotnetToolSettings = FindItemInTargetLibrary(library, ToolSettingsFileName);
                if (dotnetToolSettings == null)
                {
                    throw new ToolConfigurationException(
                              CommonLocalizableStrings.MissingToolSettingsFile);
                }

                var toolConfigurationPath =
                    PackageDirectory
                    .WithSubDirectories(
                        Id.ToString(),
                        library.Version.ToNormalizedString())
                    .WithFile(dotnetToolSettings.Path);

                var configuration = ToolConfigurationDeserializer.Deserialize(toolConfigurationPath.Value);

                var entryPointFromLockFile = FindItemInTargetLibrary(library, configuration.ToolAssemblyEntryPoint);
                if (entryPointFromLockFile == null)
                {
                    throw new ToolConfigurationException(
                              string.Format(
                                  CommonLocalizableStrings.MissingToolEntryPointFile,
                                  configuration.ToolAssemblyEntryPoint,
                                  configuration.CommandName));
                }

                // Currently only "dotnet" commands are supported
                commands.Add(new CommandSettings(
                                 configuration.CommandName,
                                 "dotnet",
                                 PackageDirectory
                                 .WithSubDirectories(
                                     Id.ToString(),
                                     library.Version.ToNormalizedString())
                                 .WithFile(entryPointFromLockFile.Path)));

                return(commands);
            }
            catch (Exception ex) when(ex is UnauthorizedAccessException || ex is IOException)
            {
                throw new ToolConfigurationException(
                          string.Format(
                              CommonLocalizableStrings.FailedToRetrieveToolConfiguration,
                              ex.Message),
                          ex);
            }
        }
Example #4
0
        private IReadOnlyList <FilePath> GetPackagedShims()
        {
            LockFileTargetLibrary library;

            try
            {
                LockFile lockFile = new LockFileFormat().Read(PackageDirectory.WithFile(AssetsFileName).Value);
                library = FindLibraryInLockFile(lockFile);
            }
            catch (Exception ex) when(ex is UnauthorizedAccessException || ex is IOException)
            {
                throw new ToolPackageException(
                          string.Format(
                              CommonLocalizableStrings.FailedToReadNuGetLockFile,
                              Id,
                              ex.Message),
                          ex);
            }

            IEnumerable <LockFileItem> filesUnderShimsDirectory = library
                                                                  ?.ToolsAssemblies
                                                                  ?.Where(t => LockFileMatcher.MatchesDirectoryPath(t, PackagedShimsDirectoryConvention));

            if (filesUnderShimsDirectory == null)
            {
                return(Array.Empty <FilePath>());
            }

            IEnumerable <string> allAvailableShimRuntimeIdentifiers = filesUnderShimsDirectory
                                                                      .Select(f => f.Path.Split('\\', '/')?[4]) // ex: "tools/netcoreapp2.1/any/shims/osx-x64/demo" osx-x64 is at [4]
                                                                      .Where(f => !string.IsNullOrEmpty(f));

            if (new FrameworkDependencyFile().TryGetMostFitRuntimeIdentifier(
                    DotnetFiles.VersionFileObject.BuildRid,
                    allAvailableShimRuntimeIdentifiers.ToArray(),
                    out var mostFitRuntimeIdentifier))
            {
                return(library
                       ?.ToolsAssemblies
                       ?.Where(l =>
                               LockFileMatcher.MatchesDirectoryPath(l, $"{PackagedShimsDirectoryConvention}/{mostFitRuntimeIdentifier}"))
                       .Select(l => LockFileRelativePathToFullFilePath(l.Path, library)).ToArray()
                       ?? Array.Empty <FilePath>());
            }
            else
            {
                return(Array.Empty <FilePath>());
            }
        }
Example #5
0
 private ToolConfiguration GetToolConfiguration()
 {
     try
     {
         var lockFile = new LockFileFormat().Read(PackageDirectory.WithFile(AssetsFileName).Value);
         var library  = FindLibraryInLockFile(lockFile);
         return(DeserializeToolConfiguration(ToolSettingsFileName, library));
     }
     catch (Exception ex) when(ex is UnauthorizedAccessException || ex is IOException)
     {
         throw new ToolConfigurationException(
                   string.Format(
                       CommonLocalizableStrings.FailedToRetrieveToolConfiguration,
                       ex.Message),
                   ex);
     }
 }
Example #6
0
        private IReadOnlyList <CommandSettings> GetCommands()
        {
            try
            {
                var      commands             = new List <CommandSettings>();
                LockFile lockFile             = new LockFileFormat().Read(PackageDirectory.WithFile(AssetsFileName).Value);
                LockFileTargetLibrary library = FindLibraryInLockFile(lockFile);

                ToolConfiguration configuration          = _toolConfiguration.Value;
                LockFileItem      entryPointFromLockFile = FindItemInTargetLibrary(library, configuration.ToolAssemblyEntryPoint);
                if (entryPointFromLockFile == null)
                {
                    throw new ToolConfigurationException(
                              string.Format(
                                  CommonLocalizableStrings.MissingToolEntryPointFile,
                                  configuration.ToolAssemblyEntryPoint,
                                  configuration.CommandName));
                }

                // Currently only "dotnet" commands are supported
                commands.Add(new CommandSettings(
                                 configuration.CommandName,
                                 "dotnet",
                                 LockFileRelativePathToFullFilePath(entryPointFromLockFile.Path, library)));

                return(commands);
            }
            catch (Exception ex) when(ex is UnauthorizedAccessException || ex is IOException)
            {
                throw new ToolConfigurationException(
                          string.Format(
                              CommonLocalizableStrings.FailedToRetrieveToolConfiguration,
                              ex.Message),
                          ex);
            }
        }