Example #1
0
        /// <summary>
        ///     Get path on disk to the referenced SDK.
        /// </summary>
        /// <param name="sdk">SDK referenced by the Project.</param>
        /// <param name="loggingContext">The logging service</param>
        /// <param name="sdkReferenceLocation">Location of the element within the project which referenced the SDK.</param>
        /// <param name="solutionPath">Path to the solution if known.</param>
        /// <param name="projectPath">Path to the project being built.</param>
        /// <returns>Path to the root of the referenced SDK.</returns>
        internal string GetSdkPath(SdkReference sdk, LoggingContext loggingContext,
                                   ElementLocation sdkReferenceLocation, string solutionPath, string projectPath)
        {
            ErrorUtilities.VerifyThrowInternalNull(sdk, nameof(sdk));
            ErrorUtilities.VerifyThrowInternalNull(loggingContext, nameof(loggingContext));
            ErrorUtilities.VerifyThrowInternalNull(sdkReferenceLocation, nameof(sdkReferenceLocation));

            if (_resolvers == null)
            {
                Initialize(loggingContext, sdkReferenceLocation);
            }

            var results = new List <SdkResultImpl>();

            try
            {
                var buildEngineLogger = new SdkLoggerImpl(loggingContext);
                foreach (var sdkResolver in _resolvers)
                {
                    var context       = new SdkResolverContextImpl(buildEngineLogger, projectPath, solutionPath, ProjectCollection.Version);
                    var resultFactory = new SdkResultFactoryImpl(sdk);
                    try
                    {
                        var result = (SdkResultImpl)sdkResolver.Resolve(sdk, context, resultFactory);
                        if (result != null && result.Success)
                        {
                            LogWarnings(loggingContext, sdkReferenceLocation, result);
                            return(result.Path);
                        }

                        results.Add(result);
                    }
                    catch (Exception e)
                    {
                        loggingContext.LogFatalBuildError(e, new BuildEventFileInfo(sdkReferenceLocation));
                    }
                }
            }
            catch (Exception e)
            {
                loggingContext.LogFatalBuildError(e, new BuildEventFileInfo(sdkReferenceLocation));
                throw;
            }

            foreach (var result in results)
            {
                LogWarnings(loggingContext, sdkReferenceLocation, result);

                if (result.Errors != null)
                {
                    foreach (var error in result.Errors)
                    {
                        loggingContext.LogErrorFromText(subcategoryResourceName: null, errorCode: null,
                                                        helpKeyword: null, file: new BuildEventFileInfo(sdkReferenceLocation), message: error);
                    }
                }
            }

            return(null);
        }
Example #2
0
        /// <summary>
        ///     Get path on disk to the referenced SDK.
        /// </summary>
        /// <param name="sdk">SDK referenced by the Project.</param>
        /// <param name="logger">Logging service.</param>
        /// <param name="buildEventContext">Build event context for logging.</param>
        /// <param name="projectFile">Location of the element within the project which referenced the SDK.</param>
        /// <param name="solutionPath">Path to the solution if known.</param>
        /// <returns>Path to the root of the referenced SDK.</returns>
        internal string GetSdkPath(SdkReference sdk, ILoggingService logger, MSBuildContext buildEventContext,
                                   string projectFile, string solutionPath)
        {
            if (_resolvers == null)
            {
                Initialize(logger);
            }

            var results = new List <SdkResultImpl> ();

            try {
                var buildEngineLogger = new SdkLoggerImpl(logger, buildEventContext);
                foreach (var sdkResolver in _resolvers)
                {
                    var context       = new SdkResolverContextImpl(buildEngineLogger, projectFile, solutionPath, msbuildVersion);
                    var resultFactory = new SdkResultFactoryImpl(sdk);
                    try {
                        var result = (SdkResultImpl)sdkResolver.Resolve(sdk, context, resultFactory);
                        if (result != null && result.Success)
                        {
                            LogWarnings(logger, buildEventContext, projectFile, result);
                            return(result.Path);
                        }

                        if (result != null)
                        {
                            results.Add(result);
                        }
                    } catch (Exception e) {
                        logger.LogFatalBuildError(buildEventContext, e, projectFile);
                    }
                }
            } catch (Exception e) {
                logger.LogFatalBuildError(buildEventContext, e, projectFile);
                throw;
            }

            foreach (var result in results)
            {
                LogWarnings(logger, buildEventContext, projectFile, result);

                if (result.Errors != null)
                {
                    foreach (var error in result.Errors)
                    {
                        logger.LogErrorFromText(buildEventContext, subcategoryResourceName: null, errorCode: null,
                                                helpKeyword: null, file: projectFile, message: error);
                    }
                }
            }

            return(null);
        }
Example #3
0
        /// <summary>
        ///     Get path on disk to the referenced SDK.
        /// </summary>
        /// <param name="sdk">SDK referenced by the Project.</param>
        /// <param name="logger">Logging service.</param>
        /// <param name="buildEventContext">Build event context for logging.</param>
        /// <param name="projectFile">Location of the element within the project which referenced the SDK.</param>
        /// <param name="solutionPath">Path to the solution if known.</param>
        /// <returns>Path to the root of the referenced SDK.</returns>
        internal string GetSdkPath(SdkReference sdk, ILoggingService logger, MSBuildContext buildEventContext,
                                   string projectFile, string solutionPath)
        {
            if (_resolvers == null)
            {
                Initialize(logger);
            }

            var results = new List <SdkResultImpl> ();

            try {
                var buildEngineLogger = new SdkLoggerImpl(logger, buildEventContext);
                foreach (var sdkResolver in _resolvers)
                {
                    var context       = new SdkResolverContextImpl(buildEngineLogger, projectFile, solutionPath, msbuildVersion);
                    var resultFactory = new SdkResultFactoryImpl(sdk);
                    try {
                        var result = (SdkResultImpl)sdkResolver.Resolve(sdk, context, resultFactory);
                        if (result != null && result.Success)
                        {
                            LogWarnings(logger, buildEventContext, projectFile, result);
                            return(result.Path);
                        }

                        if (result != null)
                        {
                            results.Add(result);
                        }
                    } catch (Exception e) {
                        logger.LogFatalBuildError(buildEventContext, e, projectFile);
                    }
                }
            } catch (Exception e) {
                logger.LogFatalBuildError(buildEventContext, e, projectFile);
                throw;
            }

            StringBuilder errorMessage = null;

            foreach (var result in results)
            {
                LogWarnings(logger, buildEventContext, projectFile, result);

                if (result.Errors != null)
                {
                    foreach (var error in result.Errors)
                    {
                        logger.LogErrorFromText(buildEventContext, subcategoryResourceName: null, errorCode: null,
                                                helpKeyword: null, file: projectFile, message: error);

                        if (errorMessage == null)
                        {
                            errorMessage = StringBuilderCache.Allocate();
                        }
                        errorMessage.AppendLine(error);
                    }
                }
            }

            if (errorMessage != null)
            {
                throw new UserException(
                          GettextCatalog.GetString("Unable to find SDK '{0}'", sdk),
                          StringBuilderCache.ReturnAndFree(errorMessage));
            }

            return(null);
        }