コード例 #1
0
        private IReadOnlyList <CommandSettings> GetCommands()
        {
            try
            {
                var commands = new List <CommandSettings>();
                var lockFile = new LockFileFormat().Read(PackageDirectory.WithFile(AssetsFileName).Value);

                var library = FindLibraryInLockFile(lockFile);
                ToolConfiguration configuration = DeserializeToolConfiguration(ToolSettingsFileName, library);

                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);
            }
        }
コード例 #2
0
ファイル: ToolPackageObtainer.cs プロジェクト: wei12/cli
        public ToolConfigurationAndExecutableDirectory ObtainAndReturnExecutablePath(
            string packageId,
            string packageVersion  = null,
            FilePath?nugetconfig   = null,
            string targetframework = null)
        {
            if (packageId == null)
            {
                throw new ArgumentNullException(nameof(packageId));
            }

            if (nugetconfig != null)
            {
                if (!File.Exists(nugetconfig.Value.Value))
                {
                    throw new PackageObtainException($"NuGet configuration file {Path.GetFullPath(nugetconfig.Value.Value)} does not exist.");
                }
            }

            if (targetframework == null)
            {
                targetframework = _bundledTargetFrameworkMoniker.Value;
            }

            var packageVersionOrPlaceHolder = new PackageVersion(packageVersion);

            DirectoryPath toolDirectory =
                CreateIndividualToolVersionDirectory(packageId, packageVersionOrPlaceHolder);

            FilePath tempProjectPath = CreateTempProject(
                packageId,
                packageVersionOrPlaceHolder,
                targetframework,
                toolDirectory);

            if (packageVersionOrPlaceHolder.IsPlaceholder)
            {
                InvokeAddPackageRestore(
                    nugetconfig,
                    tempProjectPath,
                    packageId);
            }

            InvokeRestore(nugetconfig: nugetconfig, tempProjectPath: tempProjectPath, individualToolVersion: toolDirectory);

            if (packageVersionOrPlaceHolder.IsPlaceholder)
            {
                var concreteVersion =
                    new DirectoryInfo(
                        Directory.GetDirectories(
                            toolDirectory.WithSubDirectories(packageId).Value).Single()).Name;
                DirectoryPath versioned =
                    toolDirectory.GetParentPath().WithSubDirectories(concreteVersion);

                MoveToVersionedDirectory(versioned, toolDirectory);

                toolDirectory  = versioned;
                packageVersion = concreteVersion;
            }

            ToolConfiguration toolConfiguration = GetConfiguration(packageId: packageId, packageVersion: packageVersion, individualToolVersion: toolDirectory);

            return(new ToolConfigurationAndExecutableDirectory(
                       toolConfiguration,
                       toolDirectory.WithSubDirectories(
                           packageId,
                           packageVersion,
                           "tools",
                           targetframework,
                           "any")));
        }
コード例 #3
0
ファイル: ToolPackageObtainer.cs プロジェクト: yanchenw/cli
        private ToolConfigurationAndExecutablePath ObtainAndReturnExecutablePathInStageFolder(
            string packageId,
            DirectoryPath stageDirectory,
            string packageVersion  = null,
            FilePath?nugetconfig   = null,
            string targetframework = null,
            string source          = null,
            string verbosity       = null)
        {
            if (packageId == null)
            {
                throw new ArgumentNullException(nameof(packageId));
            }

            if (nugetconfig != null)
            {
                if (!File.Exists(nugetconfig.Value.Value))
                {
                    throw new PackageObtainException(
                              string.Format(CommonLocalizableStrings.NuGetConfigurationFileDoesNotExist,
                                            Path.GetFullPath(nugetconfig.Value.Value)));
                }
            }

            if (targetframework == null)
            {
                targetframework = _bundledTargetFrameworkMoniker.Value;
            }

            var packageVersionOrPlaceHolder = new PackageVersion(packageVersion);

            DirectoryPath nugetSandboxDirectory =
                CreateNugetSandboxDirectory(packageVersionOrPlaceHolder, stageDirectory);

            FilePath tempProjectPath = CreateTempProject(
                packageId,
                packageVersionOrPlaceHolder,
                targetframework,
                nugetSandboxDirectory);

            _projectRestorer.Restore(tempProjectPath, nugetSandboxDirectory, nugetconfig, source, verbosity);

            if (packageVersionOrPlaceHolder.IsPlaceholder)
            {
                var concreteVersion =
                    new DirectoryInfo(
                        Directory.GetDirectories(
                            nugetSandboxDirectory.WithSubDirectories(packageId).Value).Single()).Name;
                DirectoryPath versioned =
                    nugetSandboxDirectory.GetParentPath().WithSubDirectories(concreteVersion);

                MoveToVersionedDirectory(versioned, nugetSandboxDirectory);

                nugetSandboxDirectory = versioned;
                packageVersion        = concreteVersion;
            }

            LockFile lockFile = new LockFileFormat()
                                .ReadWithLock(nugetSandboxDirectory.WithFile("project.assets.json").Value)
                                .Result;

            LockFileItem dotnetToolSettings = FindAssetInLockFile(lockFile, "DotnetToolSettings.xml", packageId);

            if (dotnetToolSettings == null)
            {
                throw new PackageObtainException(
                          string.Format(CommonLocalizableStrings.ToolPackageMissingSettingsFile, packageId));
            }

            FilePath toolConfigurationPath =
                nugetSandboxDirectory
                .WithSubDirectories(packageId, packageVersion)
                .WithFile(dotnetToolSettings.Path);

            ToolConfiguration toolConfiguration =
                ToolConfigurationDeserializer.Deserialize(toolConfigurationPath.Value);

            var entryPointFromLockFile =
                FindAssetInLockFile(lockFile, toolConfiguration.ToolAssemblyEntryPoint, packageId);

            if (entryPointFromLockFile == null)
            {
                throw new PackageObtainException(string.Format(CommonLocalizableStrings.ToolPackageMissingEntryPointFile,
                                                               packageId, toolConfiguration.ToolAssemblyEntryPoint));
            }

            return(new ToolConfigurationAndExecutablePath(
                       toolConfiguration,
                       _toolsPath.WithSubDirectories(
                           packageId,
                           packageVersion,
                           packageId,
                           packageVersion)
                       .WithFile(entryPointFromLockFile.Path)));
        }