예제 #1
0
        public static Version GetLowestNetCoreVersion(IEnumerable <string> targetFrameworks)
        {
            Version targetVersion = null;

            foreach (string targetFramework in targetFrameworks)
            {
                if (TargetFrameworkHelper.IsSupportedFramework(targetFramework, out var frameworkInfo) && frameworkInfo.IsDnx)
                {
                    Version netCoreVersion;

                    if (frameworkInfo.IsKnownDnx)
                    {
                        netCoreVersion = frameworkInfo.Name == FrameworkInfo.Netstandard ?
                                         TargetFrameworkHelper.NetStandardToNetCoreVersionMap[frameworkInfo.Version] :
                                         frameworkInfo.Version;
                    }
                    else
                    {
                        // this is a target framework not yet known to the tool, use the latest known netcore version.
                        netCoreVersion = TargetFrameworkHelper.NetStandardToNetCoreVersionMap.Values.LastOrDefault();
                    }

                    if (targetVersion == null || targetVersion > netCoreVersion)
                    {
                        targetVersion = netCoreVersion;
                    }
                }
            }

            return(targetVersion);
        }
예제 #2
0
        public async Task <IEnumerable <ProjectDependency> > ResolveProjectReferencesAsync(IEnumerable <ProjectDependency> excludeDependencies, ILogger logger, CancellationToken cancellationToken)
        {
            ThrowOnDisposed();

            IEnumerable <ProjectDependency> dependencies = null;

            if (excludeDependencies == null)
            {
                excludeDependencies = new List <ProjectDependency>();
            }

            using (var safeLogger = await SafeLogger.WriteStartOperationAsync(logger, "Resolving project references ...").ConfigureAwait(false))
            {
                if (_targetFrameworks.Count == 1 && TargetFrameworkHelper.IsSupportedFramework(this.TargetFramework, out var frameworkInfo) && frameworkInfo.IsDnx)
                {
                    await this.RestoreAsync(logger, cancellationToken).ConfigureAwait(false);

                    var packageReferences = await ResolvePackageReferencesAsync(logger, cancellationToken).ConfigureAwait(false);

                    var assemblyReferences = await ResolveAssemblyReferencesAsync(logger, cancellationToken).ConfigureAwait(false);

                    dependencies = packageReferences.Union(assemblyReferences).Except(excludeDependencies);
                }
                else
                {
                    await safeLogger.WriteWarningAsync(Shared.Resources.WarningMultiFxOrNoSupportedDnxVersion, logToUI : true).ConfigureAwait(false);

                    dependencies = new List <ProjectDependency>();
                }

                await safeLogger.WriteMessageAsync($"Resolved project reference count: {dependencies.Count()}", logToUI : false).ConfigureAwait(false);
            }

            return(dependencies);
        }
예제 #3
0
        private async Task GenerateProjectAsync(bool keepBootstrapperDir, ILogger logger, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var projectFullPath = Path.Combine(this.Options.BootstrapPath.FullName, nameof(SvcutilBootstrapper), SvcutilBootstrapper.ProjectName);

            if (keepBootstrapperDir)
            {
                // creating the directory prevents the bootstrapper project from deleting it as it doesn't own it, files will not be deleted either.
                Directory.CreateDirectory(Path.GetDirectoryName(projectFullPath));
            }

            // If the target framework was provided, it was validated already when processing params.
            // Bootstrapping is enabled only for netcoreapp or netstandard TFM, let's check.

            bool isSupportedTFM = TargetFrameworkHelper.IsSupportedFramework(this.Options.TargetFramework.FullName, out var frameworkInfo);

            Debug.Assert(frameworkInfo.IsDnx, "The bootstrapper has been enabled for a non-DNX platform!");

            ToolConsole.WriteLineIf(ToolConsole.Verbosity >= Verbosity.Verbose, Resource.CreatingProjectMsg);

            using (await SafeLogger.WriteStartOperationAsync(logger, $"Creating project file: \"{projectFullPath}\"").ConfigureAwait(false))
            {
                var svcutilPkgRef = ProjectDependency.FromAssembly(Path.Combine(Path.GetDirectoryName(Tool.FullPath), Tool.AssemblyName + ".dll"));

                this.MSBuildProj = await MSBuildProj.DotNetNewAsync(projectFullPath, logger, cancellationToken).ConfigureAwait(false);

                this.MSBuildProj.AddDependency(svcutilPkgRef);

                // NOTE: If post v2.0 NetStandard ships a different version from NetCore the table below needs to be updated!
                var targetFramework = frameworkInfo.FullName;
                if (isSupportedTFM && frameworkInfo.IsKnownDnx)
                {
                    if (frameworkInfo.Name == FrameworkInfo.Netstandard)
                    {
                        targetFramework = FrameworkInfo.Netcoreapp + TargetFrameworkHelper.NetStandardToNetCoreVersionMap[frameworkInfo.Version];
                    }
                    this.MSBuildProj.TargetFramework = targetFramework;
                }
                // else
                // The TFM is unknown: either, it was not provided or it is a version not yet known to the tool,
                // we will use the default TF from the generated project.
            }

            foreach (ProjectDependency dependency in this.Options.References)
            {
                this.MSBuildProj.AddDependency(dependency);
            }

            if (!string.IsNullOrEmpty(this.Options.RuntimeIdentifier))
            {
                this.MSBuildProj.RuntimeIdentifier = this.Options.RuntimeIdentifier;
            }

            // Don't treat warnings as errors so the bootstrapper will succeed as often as possible.
            this.MSBuildProj.ClearWarningsAsErrors();

            await this.MSBuildProj.SaveAsync(logger, cancellationToken).ConfigureAwait(false);
        }
예제 #4
0
        public static bool ContainsFullFrameworkTarget(IEnumerable <string> targetFrameworks)
        {
            foreach (string targetFramework in targetFrameworks)
            {
                if (TargetFrameworkHelper.IsSupportedFramework(targetFramework, out var frameworkInfo) && !frameworkInfo.IsDnx)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #5
0
        public static Version GetLowestNetCoreVersion(IEnumerable <string> targetFrameworks)
        {
            Version targetVersion = null;

            foreach (string targetFramework in targetFrameworks)
            {
                if (TargetFrameworkHelper.IsSupportedFramework(targetFramework, out var frameworkInfo) && frameworkInfo.IsDnx)
                {
                    Version netCoreVersion;

                    if (frameworkInfo.IsKnownDnx)
                    {
                        netCoreVersion = frameworkInfo.Name == FrameworkInfo.Netstandard ?
                                         TargetFrameworkHelper.NetStandardToNetCoreVersionMap[frameworkInfo.Version] :
                                         frameworkInfo.Version;
                    }
                    else
                    {
                        // target framework is not the minumum standard supported netcore version but it is a known shipped netcore version.
                        if (TargetFrameworkHelper.NetCoreVersionReferenceTable.ContainsKey(frameworkInfo.Version))
                        {
                            netCoreVersion = frameworkInfo.Version;
                        }
                        else
                        {
                            // target framework is not known to the tool, use the latest known netcore version.
                            netCoreVersion = TargetFrameworkHelper.NetCoreVersionReferenceTable.Keys.LastOrDefault();
                        }
                    }

                    if (targetVersion == null || targetVersion > netCoreVersion)
                    {
                        targetVersion = netCoreVersion;
                    }
                }
            }

            return(targetVersion);
        }