示例#1
0
            public override SdkResultBase Resolve(SdkReference sdk, SdkResolverContextBase resolverContext, SdkResultFactoryBase factory)
            {
                resolverContext.Logger.LogMessage("MockSdkResolverWithResolvableSdkPattern1 running", MessageImportance.Normal);

                if (sdk.Name.StartsWith("11"))
                {
                    return(factory.IndicateSuccess("resolverpathwithresolvablesdkpattern1", "version3"));
                }

                return(factory.IndicateFailure(new[] { "ERROR3" }));
            }
示例#2
0
 public override SdkResultBase Resolve(SdkReference sdkReference, SdkResolverContextBase resolverContext, SdkResultFactoryBase factory) => null;
示例#3
0
            public override SdkResultBase Resolve(SdkReference sdk, SdkResolverContextBase resolverContext, SdkResultFactoryBase factory)
            {
                resolverContext.Logger.LogMessage("MockSdkResolver2 running", MessageImportance.Normal);

                if (sdk.Name.StartsWith("2"))
                {
                    return(factory.IndicateSuccess("resolverpath2", "version2", new[] { "WARNING2" }));
                }

                return(factory.IndicateFailure(new[] { "ERROR2" }, new[] { "WARNING2" }));
            }
            public override Framework.SdkResult Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory)
            {
                ResolvedCalls.AddOrUpdate(sdkReference.Name, k => 1, (k, c) => c + 1);

                return(_resultMap.TryGetValue(sdkReference.Name, out var result)
                    ? new SdkResult(sdkReference, result.Path, result.Version, null)
                    : null);
            }
            public override Framework.SdkResult Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory)
            {
                resolverContext.Logger.LogMessage($"{nameof(resolverContext.ProjectFilePath)} = {resolverContext.ProjectFilePath}", MessageImportance.High);
                resolverContext.Logger.LogMessage($"{nameof(resolverContext.SolutionFilePath)} = {resolverContext.SolutionFilePath}", MessageImportance.High);
                resolverContext.Logger.LogMessage($"{nameof(resolverContext.MSBuildVersion)} = {resolverContext.MSBuildVersion}", MessageImportance.High);

                return(_mapping.ContainsKey(sdkReference.Name)
                    ? factory.IndicateSuccess(_mapping[sdkReference.Name], null)
                    : factory.IndicateFailure(new[] { $"Not in {nameof(_mapping)}" }));
            }
示例#6
0
            public override SdkResultBase Resolve(SdkReference sdk, SdkResolverContextBase resolverContext, SdkResultFactoryBase factory)
            {
                resolverContext.Logger.LogMessage("MockSdkResolverThrows running", MessageImportance.Normal);

                throw new ArithmeticException("EXMESSAGE");
            }
示例#7
0
 public override SdkResultBase Resolve(SdkReference sdkReference, SdkResolverContextBase resolverContext, SdkResultFactoryBase factory)
 {
     throw new NotImplementedException();
 }
示例#8
0
            public override SdkResultBase Resolve(SdkReference sdkReference, SdkResolverContextBase resolverContext, SdkResultFactoryBase factory)
            {
                if (sdkReference.Name.Equals("notfound"))
                {
                    return(null);
                }
                if (resolverContext.State != null)
                {
                    return(factory.IndicateSuccess((string)resolverContext.State, "1.0"));
                }

                resolverContext.State = Expected;

                return(factory.IndicateSuccess("resolverpath", "1.0"));
            }
示例#9
0
        public override SdkResultBase Resolve(SdkReference sdk, SdkResolverContextBase context, SdkResultFactoryBase factory)
        {
            var sdkPath = Path.Combine(BuildEnvironmentHelper.Instance.MSBuildSDKsPath, sdk.Name, "Sdk");

            // Note: On failure MSBuild will log a generic message, no need to indicate a failure reason here.
            return(FileUtilities.DirectoryExistsNoThrow(sdkPath)
                ? factory.IndicateSuccess(sdkPath, string.Empty)
                : factory.IndicateFailure(null));
        }
示例#10
0
            public override Framework.SdkResult Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory)
            {
                if (_resolveFunc != null)
                {
                    return(_resolveFunc(sdkReference, resolverContext, factory));
                }

                ResolvedCalls.AddOrUpdate(sdkReference.Name, k => 1, (k, c) => c + 1);

                return(_resultMap.TryGetValue(sdkReference.Name, out var result)
                    ? CloneSdkResult(result)
                    : null);
            }
示例#11
0
            public static SdkResultBase GetSdkResult(SdkReference sdk, object nuGetVersion, SdkResolverContextBase context, SdkResultFactoryBase factory)
            {
                // Cast the NuGet version since the caller does not want to consume NuGet classes directly
                NuGetVersion parsedSdkVersion = (NuGetVersion)nuGetVersion;

                // Stores errors and warnings for the result
                ICollection <string> errors   = new List <string>();
                ICollection <string> warnings = new List <string>();

                // Load NuGet settings and a path resolver
                ISettings settings = Settings.LoadDefaultSettings(context.ProjectFilePath);

                FallbackPackagePathResolver fallbackPackagePathResolver = new FallbackPackagePathResolver(NuGetPathContext.Create(settings));

                string installedPath, installedVersion;

                // Attempt to find a package if its already installed
                if (!TryGetMSBuildSdkPackageInfo(fallbackPackagePathResolver, sdk.Name, parsedSdkVersion, out installedPath, out installedVersion))
                {
                    try
                    {
                        // Asynchronously run the restore without a commit which find the package on configured feeds, download, and unzip it without generating any other files
                        IReadOnlyList <RestoreResultPair> results = RestoreRunnerEx.RunWithoutCommit(
                            context.ProjectFilePath,
                            sdk.Name,
                            parsedSdkVersion.ToFullString(),
                            settings,
                            new NuGetSdkLogger(context.Logger, warnings, errors))
                                                                    .ConfigureAwait(continueOnCapturedContext: false)
                                                                    .GetAwaiter()
                                                                    .GetResult();

                        fallbackPackagePathResolver = new FallbackPackagePathResolver(NuGetPathContext.Create(settings));

                        // Look for a successful result, any errors are logged by NuGet
                        foreach (RestoreResult result in results.Select(i => i.Result).Where(i => i.Success))
                        {
                            // Find the information about the package that was installed.  In some cases, the version can be different than what was specified (like you specify 1.0 but get 1.0.0)
                            LibraryIdentity installedPackage = result.GetAllInstalled().FirstOrDefault(i => i.Name.Equals(sdk.Name));

                            if (installedPackage != null)
                            {
                                if (!TryGetMSBuildSdkPackageInfo(fallbackPackagePathResolver, installedPackage.Name, installedPackage.Version, out installedPath, out installedVersion))
                                {
                                    // This should never happen because we were told the package was successfully installed.
                                    // If we can't find it, we probably did something wrong with the NuGet API
                                    errors.Add(ResourceUtilities.FormatResourceString("CouldNotFindInstalledPackage", sdk));
                                }
                            }
                            else
                            {
                                // This should never happen because we were told the restore succeeded.
                                // If we can't find the package from GetAllInstalled(), we probably did something wrong with the NuGet API
                                errors.Add(ResourceUtilities.FormatResourceString("PackageWasNotInstalled", sdk, sdk.Name));
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        errors.Add(e.Message);
                    }
                }

                if (errors.Count == 0)
                {
                    return(factory.IndicateSuccess(path: installedPath, version: installedVersion, warnings: warnings));
                }

                return(factory.IndicateFailure(errors, warnings));
            }
示例#12
0
        protected override SdkResultBase ResolveSdk(SdkReference sdk, SdkResolverContextBase context, SdkResultFactoryBase factory)
        {
            object parsedSdkVersion;

            // This resolver only works if the user specifies a version in a project or a global.json.
            // Ignore invalid versions, there may be another resolver that can handle the version specified
            if (!TryGetNuGetVersionForSdk(sdk.Name, sdk.Version, context, out parsedSdkVersion))
            {
                return(null);
            }

            return(NuGetAbstraction.GetSdkResult(sdk, parsedSdkVersion, context, factory));
        }