// Trying to fetch a property value from tfm property bags.
 // If defined the property should have identical values in all of the occurances.
 private static TValue GetSingleNonEvaluatedPropertyOrNull <TValue>(
     IVsTargetFrameworks tfms,
     string propertyName,
     Func <string, TValue> valueFactory)
 {
     return(GetNonEvaluatedPropertyOrNull(tfms, propertyName, valueFactory).SingleOrDefault());
 }
        /// <summary>
        /// The result will contain CLEAR and no sources specified in RestoreFallbackFolders if the clear keyword is in it.
        /// If there are additional fallback folders specified, the value AdditionalValue will be set in the result and then all the additional fallback folders will follow
        /// </summary>
        private static IEnumerable <string> GetRestoreFallbackFolders(IVsTargetFrameworks tfms)
        {
            var folders = HandleClear(MSBuildStringUtility.Split(GetNonEvaluatedPropertyOrNull(tfms, RestoreFallbackFolders, e => e)));

            var additional = MSBuildStringUtility.Split(GetNonEvaluatedPropertyOrNull(tfms, RestoreAdditionalProjectFallbackFolders, e => e));

            return(VSRestoreSettingsUtilities.GetEntriesWithAdditional(folders, additional));
        }
        private static IEnumerable <NuGetLogCode> GetSingleOrDefaultNuGetLogCodes(
            IVsTargetFrameworks tfms,
            string propertyName,
            Func <string, IEnumerable <NuGetLogCode> > valueFactory)
        {
            var logCodeProperties = GetNonEvaluatedPropertyOrNull(tfms, propertyName, valueFactory);

            return(MSBuildStringUtility.GetDistinctNuGetLogCodesOrDefault(logCodeProperties));
        }
        private static TValue GetSingleOrDefaultPropertyValue <TValue>(
            IVsTargetFrameworks tfms,
            string propertyName,
            Func <string, TValue> valueFactory)
        {
            var properties = GetNonEvaluatedPropertyOrNull(tfms, propertyName, valueFactory);

            return(properties.Count() > 1 ? default(TValue) : properties.SingleOrDefault());
        }
Esempio n. 5
0
        private static NuGetVersion GetPackageVersion(IVsTargetFrameworks tfms)
        {
            // $(PackageVersion) property if set overrides the $(Version)
            var versionPropertyValue =
                GetNonEvaluatedPropertyOrNull(tfms, PackageVersion, NuGetVersion.Parse)
                ?? GetNonEvaluatedPropertyOrNull(tfms, Version, NuGetVersion.Parse);

            return(versionPropertyValue ?? PackageSpec.DefaultVersion);
        }
Esempio n. 6
0
 /// <summary>
 /// Fetch all property values from each target framework and combine them.
 /// </summary>
 private static IEnumerable <string> GetAggregatePropertyValues(
     IVsTargetFrameworks tfms,
     string propertyName)
 {
     // Only non-null values are added to the list as part of the split.
     return(tfms
            .Cast <IVsTargetFrameworkInfo>()
            .SelectMany(tfm => MSBuildStringUtility.Split(GetPropertyValueOrNull(tfm.Properties, propertyName))));
 }
        private static IEnumerable <string> GetRestoreFallbackFolders(IVsTargetFrameworks tfms)
        {
            var folders = MSBuildStringUtility.Split(GetNonEvaluatedPropertyOrNull(tfms, RestoreFallbackFolders, e => e));

            folders = HandleClear(folders);

            var additional = MSBuildStringUtility.Split(GetNonEvaluatedPropertyOrNull(tfms, RestoreAdditionalProjectFallbackFolders, e => e));

            return(folders.Concat(additional));
        }
Esempio n. 8
0
        private static void LogTargetFrameworks(IProjectLoggerBatch logger, IVsTargetFrameworks targetFrameworks)
        {
            logger.WriteLine($"Target Frameworks ({targetFrameworks.Count})");
            logger.IndentLevel++;

            foreach (IVsTargetFrameworkInfo tf in targetFrameworks)
            {
                LogTargetFramework(logger, tf);
            }
            logger.IndentLevel--;
        }
Esempio n. 9
0
        public ProjectRestoreInfo(string msbuildProjectExtensionsPath, string originalTargetFrameworks, IVsTargetFrameworks targetFrameworks, IVsReferenceItems toolReferences)
        {
            Requires.NotNull(msbuildProjectExtensionsPath, nameof(msbuildProjectExtensionsPath));
            Requires.NotNull(originalTargetFrameworks, nameof(originalTargetFrameworks));
            Requires.NotNull(targetFrameworks, nameof(targetFrameworks));
            Requires.NotNull(toolReferences, nameof(toolReferences));

            MSBuildProjectExtensionsPath = msbuildProjectExtensionsPath;
            OriginalTargetFrameworks     = originalTargetFrameworks;
            TargetFrameworks             = targetFrameworks;
            ToolReferences = toolReferences;
        }
Esempio n. 10
0
        /// <summary>
        /// The result will contain CLEAR and no sources specified in RestoreSources if the clear keyword is in it.
        /// If there are additional sources specified, the value AdditionalValue will be set in the result and then all the additional sources will follow
        /// </summary>
        private static IEnumerable <string> GetRestoreSources(IVsTargetFrameworks tfms)
        {
            var sources = HandleClear(MSBuildStringUtility.Split(GetNonEvaluatedPropertyOrNull(tfms, RestoreSources, e => e)));

            // Read RestoreAdditionalProjectSources from the inner build, these may be different between frameworks.
            // Exclude is not allowed for sources
            var additional = MSBuildRestoreUtility.AggregateSources(
                values: GetAggregatePropertyValues(tfms, RestoreAdditionalProjectSources),
                excludeValues: Enumerable.Empty <string>());

            return(VSRestoreSettingsUtilities.GetEntriesWithAdditional(sources, additional.ToArray()));
        }
Esempio n. 11
0
        /// <summary>
        /// The result will contain CLEAR and no sources specified in RestoreFallbackFolders if the clear keyword is in it.
        /// If there are additional fallback folders specified, the value AdditionalValue will be set in the result and then all the additional fallback folders will follow
        /// </summary>
        private static IEnumerable <string> GetRestoreFallbackFolders(IVsTargetFrameworks tfms)
        {
            var folders = HandleClear(MSBuildStringUtility.Split(GetNonEvaluatedPropertyOrNull(tfms, RestoreFallbackFolders, e => e)));

            // Read RestoreAdditionalProjectFallbackFolders from the inner build.
            // Remove all excluded fallback folders listed in RestoreAdditionalProjectFallbackFoldersExcludes.
            var additional = MSBuildRestoreUtility.AggregateSources(
                values: GetAggregatePropertyValues(tfms, RestoreAdditionalProjectFallbackFolders),
                excludeValues: GetAggregatePropertyValues(tfms, RestoreAdditionalProjectFallbackFoldersExcludes));

            return(VSRestoreSettingsUtilities.GetEntriesWithAdditional(folders, additional.ToArray()));
        }
        private static string[] GetRestoreSources(IVsTargetFrameworks tfms)
        {
            var sources = MSBuildStringUtility.Split(GetNonEvaluatedPropertyOrNull(tfms, RestoreSources, e => e));

            sources = HandleClear(sources);

            var additional = MSBuildStringUtility.Split(GetNonEvaluatedPropertyOrNull(tfms, RestoreAdditionalProjectSources, e => e));

            sources = sources.Concat(additional).ToArray();

            return(sources);
        }
Esempio n. 13
0
        public ProjectRestoreInfo(string baseIntermediatePath, string originalTargetFrameworks, IVsTargetFrameworks targetFrameworks, IVsReferenceItems toolReferences)
        {
            Requires.NotNullOrEmpty(baseIntermediatePath, nameof(baseIntermediatePath));
            Requires.NotNull(originalTargetFrameworks, nameof(originalTargetFrameworks));
            Requires.NotNull(targetFrameworks, nameof(targetFrameworks));
            Requires.NotNull(toolReferences, nameof(toolReferences));

            BaseIntermediatePath     = baseIntermediatePath;
            OriginalTargetFrameworks = originalTargetFrameworks;
            TargetFrameworks         = targetFrameworks;
            ToolReferences           = toolReferences;
        }
 // Trying to fetch a list of property value from all tfm property bags.
 private static IEnumerable <TValue> GetNonEvaluatedPropertyOrNull <TValue>(
     IVsTargetFrameworks tfms,
     string propertyName,
     Func <string, TValue> valueFactory)
 {
     return(tfms
            .Cast <IVsTargetFrameworkInfo>()
            .Select(tfm =>
     {
         var val = GetPropertyValueOrNull(tfm.Properties, propertyName);
         return val != null ? valueFactory(val) : default(TValue);
     })
            .Distinct());
 }
Esempio n. 15
0
        public VsProjectRestoreInfo(
            string baseIntermediatePath,
            IVsTargetFrameworks targetFrameworks)
        {
            if (string.IsNullOrEmpty(baseIntermediatePath))
            {
                throw new ArgumentException(ProjectManagement.Strings.Argument_Cannot_Be_Null_Or_Empty, nameof(baseIntermediatePath));
            }

            if (targetFrameworks == null)
            {
                throw new ArgumentNullException(nameof(targetFrameworks));
            }

            BaseIntermediatePath = baseIntermediatePath;
            TargetFrameworks     = targetFrameworks;
        }
Esempio n. 16
0
        public VsProjectRestoreInfo(
            string baseIntermediatePath,
            IVsTargetFrameworks targetFrameworks)
        {
            if (string.IsNullOrEmpty(baseIntermediatePath))
            {
                throw new ArgumentException("Argument cannot be null or empty", nameof(baseIntermediatePath));
            }

            if (targetFrameworks == null)
            {
                throw new ArgumentNullException(nameof(targetFrameworks));
            }

            BaseIntermediatePath = baseIntermediatePath;
            TargetFrameworks     = targetFrameworks;
        }
Esempio n. 17
0
        private IVsProjectRestoreInfo MergeRestoreData(IReadOnlyCollection <ProjectRestoreUpdate> updates)
        {
            // We have no active configuration
            if (updates.Count == 0)
            {
                return(null);
            }

            // We need to combine the snapshots from each implicitly active configuration (ie per TFM),
            // resolving any conflicts, which we'll report to the user.

            string              msbuildProjectExtensionsPath = ResolveMSBuildProjectExtensionsPathConflicts(updates);
            string              originalTargetFrameworks     = ResolveOriginalTargetFrameworksConflicts(updates);
            IVsReferenceItems   toolReferences   = ResolveToolReferenceConflicts(updates);
            IVsTargetFrameworks targetFrameworks = GetAllTargetFrameworks(updates);

            return(new ProjectRestoreInfo(
                       msbuildProjectExtensionsPath,
                       originalTargetFrameworks,
                       targetFrameworks,
                       toolReferences));
        }
 private static string GetRestorePackagesWithLockFile(IVsTargetFrameworks tfms)
 {
     return(GetSingleNonEvaluatedPropertyOrNull(tfms, RestorePackagesWithLockFile, v => v));
 }
Esempio n. 19
0
 private static string GetRestoreProjectPath(IVsTargetFrameworks tfms)
 {
     return(GetNonEvaluatedPropertyOrNull(tfms, RestorePackagesPath, e => e));
 }
 private static string GetNuGetLockFilePath(IVsTargetFrameworks tfms)
 {
     return(GetSingleNonEvaluatedPropertyOrNull(tfms, NuGetLockFilePath, v => v));
 }
Esempio n. 21
0
        private static string GetPackageId(ProjectNames projectNames, IVsTargetFrameworks tfms)
        {
            var packageId = GetNonEvaluatedPropertyOrNull(tfms, PackageId, v => v);

            return(packageId ?? projectNames.ShortName);
        }
 private static bool IsLockFileFreezeOnRestore(IVsTargetFrameworks tfms)
 {
     return(GetSingleNonEvaluatedPropertyOrNull(tfms, RestoreLockedMode, MSBuildStringUtility.IsTrue));
 }