コード例 #1
0
        private static async Task <CompatibilityLevel> GetProjectCompatibilityAsync(UnconfiguredProject project, VersionCompatibilityData compatData)
        {
            if (project.Capabilities.AppliesTo($"{ProjectCapability.DotNet} & {ProjectCapability.PackageReferences}"))
            {
                IProjectProperties properties = project.Services.ActiveConfiguredProjectProvider.ActiveConfiguredProject.Services.ProjectPropertiesProvider.GetCommonProperties();
                string             tfm        = await properties.GetEvaluatedPropertyValueAsync("TargetFrameworkMoniker");

                if (!string.IsNullOrEmpty(tfm))
                {
                    var fw = new FrameworkName(tfm);
                    if (fw.Identifier.Equals(".NETCoreApp", StringComparison.OrdinalIgnoreCase))
                    {
                        return(GetCompatibilityLevelFromVersion(fw.Version, compatData));
                    }
                    else if (fw.Identifier.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase))
                    {
                        // The interesting case here is Asp.Net Core on full framework
                        IImmutableSet <IUnresolvedPackageReference> pkgReferences = await project.Services.ActiveConfiguredProjectProvider.ActiveConfiguredProject.Services.PackageReferences.GetUnresolvedReferencesAsync();

                        // Look through the package references
                        foreach (IUnresolvedPackageReference pkgRef in pkgReferences)
                        {
                            if (string.Equals(pkgRef.EvaluatedInclude, "Microsoft.AspNetCore.All", StringComparison.OrdinalIgnoreCase) ||
                                string.Equals(pkgRef.EvaluatedInclude, "Microsoft.AspNetCore", StringComparison.OrdinalIgnoreCase))
                            {
                                string verString = await pkgRef.Metadata.GetEvaluatedPropertyValueAsync("Version");

                                if (!string.IsNullOrWhiteSpace(verString))
                                {
                                    // This is a semantic version string. We only care about the non-semantic version part
                                    int index = verString.IndexOfAny(Delimiter.PlusAndMinus);
                                    if (index != -1)
                                    {
                                        verString = verString.Substring(0, index);
                                    }

                                    if (Version.TryParse(verString, out Version aspnetVersion))
                                    {
                                        return(GetCompatibilityLevelFromVersion(aspnetVersion, compatData));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(CompatibilityLevel.Recommended);
        }
コード例 #2
0
        /// <summary>
        /// Gets the application manifest kind property
        /// </summary>
        /// <remarks>
        /// The Application Manifest kind's value is one of three possibilities:
        ///     - It's the value "CustomManifest" which means the user will supply the path to a custom manifest file.
        ///     - It's the value "NoManifest" which means the application doesn't have a manifest.
        ///     - It's the value "DefaultManifest" which means that the application will have a default manifest.
        ///
        /// These three values map to two MSBuild properties - ApplicationManifest (for the first case) or NoWin32Manifest
        /// which is true for the second case and false or non-existent for the third. If those two properties aren't set
        /// then we'll use the stored value (if any) or default to DefaultManifest.
        /// </remarks>
        public override async Task <string> OnGetEvaluatedPropertyValueAsync(string propertyName, string evaluatedPropertyValue, IProjectProperties defaultProperties)
        {
            if (!string.IsNullOrEmpty(await defaultProperties.GetEvaluatedPropertyValueAsync(ApplicationManifestMSBuildProperty)))
            {
                return(CustomManifestValue);
            }

            string noManifestPropertyValue = await defaultProperties.GetEvaluatedPropertyValueAsync(NoManifestMSBuildProperty);

            if (StringComparers.PropertyLiteralValues.Equals(noManifestPropertyValue, "true"))
            {
                return(NoManifestValue);
            }

            string?storedValue = _temporaryPropertyStorage.GetPropertyValue(ApplicationManifestKindProperty);

            if (!Strings.IsNullOrEmpty(storedValue))
            {
                return(storedValue);
            }

            // It doesn't matter if it is set to false or the value is not present. We default to "DefaultManifest" scenario.
            return(DefaultManifestValue);
        }
コード例 #3
0
        public override async Task <string?> OnSetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string>?dimensionalConditions = null)
        {
            bool   isEmptyValue = string.IsNullOrEmpty(unevaluatedPropertyValue);
            string relativePath = !isEmptyValue?PathHelper.MakeRelative(_unconfiguredProject, unevaluatedPropertyValue) : string.Empty;

            string existingPropertyValue = await defaultProperties.GetEvaluatedPropertyValueAsync(_propertyName);

            IProjectItem?existingItem = await GetExistingNoneItemAsync(existingPropertyValue);

            // This default was string.Empty but caused issues for files already part of the project via globbing in the AddAsync call. It would not add the necessary
            // <PackagePath></PackagePath> node, which causes the value during pack to default to "content;contentFiles" which is not the intended directory.
            // See discussion here for more details: https://github.com/dotnet/project-system/issues/7642
            string packagePath = @"\";

            if (existingItem != null)
            {
                packagePath = await existingItem.Metadata.GetEvaluatedPropertyValueAsync(PackagePathMetadataName);

                // The new filepath is the same as the current. No item changes are required.
                if (relativePath.Equals(existingItem.EvaluatedInclude, StringComparisons.Paths))
                {
                    return(CreatePropertyValue(existingItem.EvaluatedInclude, packagePath));
                }
            }

            // None items outside of the project file cannot be updated.
            if (existingItem?.PropertiesContext.IsProjectFile ?? false)
            {
                if (!isEmptyValue)
                {
                    await existingItem.SetUnevaluatedIncludeAsync(relativePath);
                }
                else
                {
                    await existingItem.RemoveAsync();
                }
            }
            else
            {
                await _sourceItemsProvider.AddAsync(None.SchemaName, relativePath, new Dictionary <string, string>
                {
                    { PackMetadataName, bool.TrueString },
                    { PackagePathMetadataName, packagePath }
                });
            }

            return(!isEmptyValue?CreatePropertyValue(relativePath, packagePath) : string.Empty);
        }
コード例 #4
0
        public override async Task <string> OnGetEvaluatedPropertyValueAsync(string propertyName, string evaluatedPropertyValue, IProjectProperties defaultProperties)
        {
            if (!string.IsNullOrEmpty(evaluatedPropertyValue))
            {
                return(evaluatedPropertyValue);
            }

            string noManifestPropertyValue = await defaultProperties.GetEvaluatedPropertyValueAsync(NoManifestMSBuildProperty);

            if (noManifestPropertyValue?.Equals("true", StringComparison.InvariantCultureIgnoreCase) == true)
            {
                return(NoManifestValue);
            }

            // It doesn't matter if it is set to false or the value is not present. We default to "DefaultManifest" scenario.
            return(DefaultManifestValue);
        }
コード例 #5
0
        public async override Task <string> OnGetEvaluatedPropertyValueAsync(string evaluatedPropertyValue, IProjectProperties defaultProperties)
        {
            // We do the same check as in the debugger command, so empty string for the local debugger properties means we should perform
            // the interception.
            var debugCommand = await defaultProperties.GetEvaluatedPropertyValueAsync(WindowsLocalDebugger.LocalDebuggerCommandProperty).ConfigureAwait(false);

            var commandArgs = evaluatedPropertyValue;

            if (debugCommand == LocalDebuggerCommandValueProvider.DefaultCommand)
            {
                // Get the path of the executable, and plug it into "exec path original_args"
                var executable = await GetExecutablePath().ConfigureAwait(false);

                commandArgs = $"exec {executable} {commandArgs}";
            }

            return(commandArgs);
        }
コード例 #6
0
        private async Task <Result <string> > GetMacroValueAsync(string name, List <string> evaluationChain)
        {
            if (_macroCache.TryGetValue(name, out var value))
            {
                return(value);
            }

            if (evaluationChain.Contains(name))
            {
                var chain = string.Join(" -> ", evaluationChain.Append(name).Select(n => "$(" + n + ")"));
                return(new Error($"$({evaluationChain[0]}) contains a cycle: {chain}"));
            }
            evaluationChain.Add(name);

            string unevaluated = null;

            foreach (var macro in _profileOptions.Macros)
            {
                if (macro.Name == name)
                {
                    unevaluated = macro.Value;
                    break;
                }
            }

            if (unevaluated != null)
            {
                var evalResult = await EvaluateAsync(unevaluated, evaluationChain);

                if (!evalResult.TryGetResult(out value, out var error))
                {
                    return(error);
                }
            }
            else
            {
                value = await _projectProperties.GetEvaluatedPropertyValueAsync(name);
            }

            _macroCache.Add(name, value);
            return(value);
        }
コード例 #7
0
        private async Task <string> GetTargetCommandAsync(
            IProjectProperties properties,
            bool validateSettings)
        {
            // First try "RunCommand" property
            string?runCommand = await GetRunCommandAsync(properties);

            if (Strings.IsNullOrEmpty(runCommand))
            {
                // If we're launching for debug purposes, prevent someone F5'ing a class library
                if (validateSettings && await IsClassLibraryAsync())
                {
                    throw new ProjectNotRunnableDirectlyException();
                }

                // Otherwise, fall back to "TargetPath"
                runCommand = await properties.GetEvaluatedPropertyValueAsync(ConfigurationGeneral.TargetPathProperty);
            }

            return(runCommand);
        }
 public virtual Task <string> GetEvaluatedPropertyValueAsync(string propertyName)
 => DelegatedProperties.GetEvaluatedPropertyValueAsync(propertyName);
コード例 #9
0
 public override Task <string> OnGetEvaluatedPropertyValueAsync(string propertyName, string evaluatedPropertyValue, IProjectProperties defaultProperties)
 {
     return(defaultProperties.GetEvaluatedPropertyValueAsync(ApplicationManifestMSBuildProperty));
 }
コード例 #10
0
        public async Task <string> GetApplicationAsync()
        {
            var application = await userProperties.GetEvaluatedPropertyValueAsync(
                ProjectPropertyName.GgpApplication);

            return(application);
        }
コード例 #11
0
    private async Task <string> OnGetPropertyValueAsync(IProjectProperties projectProperties)
    {
        string warningLevelValue = await projectProperties.GetEvaluatedPropertyValueAsync(WarningLevelPropertyName);

        return(warningLevelValue == "0" ? "true" : "false");
    }
コード例 #12
0
        public override async Task <string> OnGetEvaluatedPropertyValueAsync(string propertyName, string evaluatedPropertyValue, IProjectProperties defaultProperties)
        {
            string win32Resource = await defaultProperties.GetEvaluatedPropertyValueAsync(Win32ResourceMSBuildProperty);

            return(ComputeValue(win32Resource));
        }
コード例 #13
0
    private async Task <ImmutableSortedSet <int> > GetWarningsAsErrorsIdsAsync(IProjectProperties projectProperties)
    {
        string warningsAsErrorsValue = await projectProperties.GetEvaluatedPropertyValueAsync(WarningsAsErrorsPropertyName);

        return(ParseIdList(warningsAsErrorsValue));
    }
コード例 #14
0
    private async Task <ImmutableSortedSet <int> > GetNoWarnIdsAsync(IProjectProperties projectProperties)
    {
        string noWarnValue = await projectProperties.GetEvaluatedPropertyValueAsync(NoWarnPropertyName);

        return(ParseIdList(noWarnValue));
    }