示例#1
0
        public async Task <InspectionValue> InspectPackageAsync(
            EnvironmentValue environment,
            InspectionKey key,
            Boolean restoreSDKPackage,
            IBuildEngine be,
            CancellationToken token
            )
        {
            const String PROCESS = "NuGetUtils.MSBuild.Exec.Inspect";

            return(await this._inspections.GetOrAdd(key, theKey => new UtilPack.AsyncLazy <InspectionValue>(async() =>
            {
                await be.LogProcessInvocationMessage(PROCESS);

                var startTime = DateTime.UtcNow;
                var env = await this.ProcessMonitor.CallProcessAndGetResultAsync <InspectConfiguration <String>, PackageInspectionResult>(
                    PROCESS,
                    new InspectConfiguration <String>()
                {
                    DisableLogging = true,
                    InspectFilePath = DefaultConfigurationConfiguration.STANDARD_INPUT_OUR_OUTPUT_MARKER,
                    NuGetConfigurationFile = key.SettingsLocation,
                    RestoreFramework = key.NuGetFramework,
                    RestoreRuntimeID = environment.ThisRuntimeID,
                    SDKFrameworkPackageID = environment.SDKPackageID,
                    SDKFrameworkPackageVersion = environment.SDKPackageVersion,
                    PackageID = key.PackageID,
                    PackageVersion = key.PackageVersion,
                    AssemblyPath = key.AssemblyPath,

                    ShutdownSemaphoreName = NuGetUtilsExecProcessMonitor.CreateNewShutdownSemaphoreName(),
                    // ReturnValuePath is not used by Inspect program
#if !NET46
                    RestoreSDKPackage = restoreSDKPackage
#endif
                },
                    token
                    );
                await be.LogProcessEndMessage(PROCESS, startTime);

                var result = env.GetFirstOrDefault();
                if (result == null)
                {
                    throw new Exception($"Errors occurred during package inspection: { env.GetSecondOrDefault() }.");
                }

                return new InspectionValue(result);
            })));
        }
示例#2
0
        public async Task <EnvironmentValue> DetectEnvironmentAsync(
            EnvironmentKeyInfo keyInfo,
            IBuildEngine be,
            CancellationToken token
            )
        {
            const String PROCESS = "NuGetUtils.MSBuild.Exec.Discover";

            return(await this._environments.GetOrAdd(keyInfo, theKeyInfo => new UtilPack.AsyncLazy <EnvironmentValue>(async() =>
            {
                var key = theKeyInfo.Key;
                var packageIDIsSelf = theKeyInfo.PackageIDIsProjectPath;

                await be.LogProcessInvocationMessage(PROCESS);
                var startTime = DateTime.UtcNow;

                var env = await this.ProcessMonitor.CallProcessAndGetResultAsync <DiscoverConfiguration <String>, EnvironmentInspectionResult>(
                    PROCESS,
                    new DiscoverConfiguration <String>()
                {
                    DisableLogging = true,
                    DiscoverFilePath = DefaultConfigurationConfiguration.STANDARD_INPUT_OUR_OUTPUT_MARKER,
                    NuGetConfigurationFile = key.SettingsLocation,
                    RestoreFramework = key.NuGetFramework,
                    RestoreRuntimeID = key.NuGetRuntimeID,
                    SDKFrameworkPackageID = key.SDKPackageID,
                    SDKFrameworkPackageVersion = key.SDKPackageVersion,
                    PackageID = packageIDIsSelf ? null : key.PackageID,
                    PackageVersion = key.PackageVersion,
                    PackageIDIsSelf = packageIDIsSelf,
                    ProjectFilePath = theKeyInfo.ProjectFilePath,

                    ShutdownSemaphoreName = NuGetUtilsExecProcessMonitor.CreateNewShutdownSemaphoreName(),
                    // ReturnValuePath, RestoreSDKPackage is not used by Discover program.
                },
                    token
                    );
                await be.LogProcessEndMessage(PROCESS, startTime);

                var result = env.GetFirstOrDefault();
                if (result == null)
                {
                    throw new Exception($"Errors occurred during environment detection: { env.GetSecondOrDefault() }.");
                }

                return new EnvironmentValue(result);
            })));
        }
示例#3
0
 internal TaskProxy(
     NuGetUtilsExecProcessMonitor processMonitor,
     InitializationArgs initializationArgs,
     EnvironmentValue environment,
     InspectionValue entrypoint,
     MethodInspectionInfo entrypointMethod,
     TypeGenerationResult generationResult
     )
 {
     this._processMonitor     = ArgumentValidator.ValidateNotNull(nameof(processMonitor), processMonitor);
     this._initializationArgs = ArgumentValidator.ValidateNotNull(nameof(initializationArgs), initializationArgs);
     this._environment        = ArgumentValidator.ValidateNotNull(nameof(environment), environment);
     this._entrypoint         = ArgumentValidator.ValidateNotNull(nameof(entrypoint), entrypoint);
     this._entrypointMethod   = ArgumentValidator.ValidateNotNull(nameof(entrypointMethod), entrypointMethod);
     this._propertyInfos      = generationResult
                                .Properties
                                .Select((p, idx) => (p, idx))
                                .ToImmutableDictionary(t => t.p.Name, t => new TaskPropertyHolder(generationResult.PropertyTypeNames[t.idx], t.p.Output, !Equals(t.p.PropertyType, typeof(String))));
     this._cancellationTokenSource = new CancellationTokenSource();
 }
示例#4
0
        public async Task <Boolean> ExecuteAsync(IBuildEngine be)
        {
            const String PROCESS = "NuGetUtils.MSBuild.Exec.Perform";
            // Call process, deserialize result, set output properties.
            var tempFileLocation = Path.Combine(Path.GetTempPath(), $"NuGetUtilsExec_" + Guid.NewGuid());

            Boolean retVal;

            try
            {
                await be.LogProcessInvocationMessage(PROCESS);

                var startTime = DateTime.UtcNow;

                var returnCode = await this._processMonitor.CallProcessAndStreamOutputAsync(
                    PROCESS,
                    new PerformConfiguration <String>
                {
                    NuGetConfigurationFile     = this._initializationArgs.SettingsLocation,
                    RestoreFramework           = this._environment.ThisFramework,
                    RestoreRuntimeID           = this._environment.ThisRuntimeID,
                    SDKFrameworkPackageID      = this._environment.SDKPackageID,
                    SDKFrameworkPackageVersion = this._environment.SDKPackageVersion,
                    PackageID      = this._environment.PackageID,
                    PackageVersion = this._entrypoint.ExactPackageVersion,
                    MethodToken    = this._entrypointMethod.MethodToken,
                    AssemblyPath   = this._initializationArgs.AssemblyPath,

                    ProjectFilePath       = be?.ProjectFileOfTaskNode,
                    ShutdownSemaphoreName = NuGetUtilsExecProcessMonitor.CreateNewShutdownSemaphoreName(),
                    ReturnValuePath       = tempFileLocation,
                    InputProperties       = new JObject(
                        this._propertyInfos
                        .Where(kvp => !kvp.Value.IsOutput)
                        .Select(kvp =>
                    {
                        var valInfo = kvp.Value;
                        var val     = valInfo.Value;
                        return(new JProperty(kvp.Key, valInfo.GetInputPropertyValue()));
                    })
                        ).ToString(Formatting.None),
                },
                    this._cancellationTokenSource.Token,
                    be == null?default(Func <String, Boolean, Task>) : (line, isError) =>
                {
                    if (isError)
                    {
                        be.LogErrorEvent(new BuildErrorEventArgs(
                                             null,
                                             null,
                                             null,
                                             -1,
                                             -1,
                                             -1,
                                             -1,
                                             line,
                                             null,
                                             NuGetExecutionTaskFactory.TASK_NAME
                                             ));
                    }
                    else
                    {
                        be.LogMessageEvent(new BuildMessageEventArgs(
                                               line,
                                               null,
                                               null,
                                               MessageImportance.High
                                               ));
                    }
                    return(null);
                }
                    );

                await be.LogProcessEndMessage(PROCESS, startTime);

                if (returnCode.HasValue && File.Exists(tempFileLocation))
                {
                    using (var sReader = new StreamReader(File.Open(tempFileLocation, FileMode.Open, FileAccess.Read, FileShare.None), new UTF8Encoding(false, false), false))
                        using (var jReader = new JsonTextReader(sReader))
                        {
                            foreach (var tuple in (JObject.Load(jReader)) // No LoadAsync in 9.0.0.
                                     .Properties()
                                     .Select(p => (p, this._propertyInfos.TryGetValue(p.Name, out var prop) ? prop : null))
                                     .Where(t => t.Item2?.IsOutput ?? false)
                                     )
                            {
                                var jProp = tuple.p;
                                this._propertyInfos[jProp.Name].Value = tuple.Item2.GetOutputPropertyValue(jProp.Value);
                            }
                        }
                }

                retVal = returnCode.HasValue && returnCode.Value == 0;
            }
            catch
            {
                if (this._cancellationTokenSource.IsCancellationRequested)
                {
                    retVal = false;
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                if (File.Exists(tempFileLocation))
                {
                    File.Delete(tempFileLocation);
                }
            }

            return(retVal);
        }