コード例 #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        internal ProjectArchivingSettings(IProjectProperties projectProperties)
        {
            Debug.Assert(null != projectProperties);

            _projectProperties = projectProperties;
            _InitArchivingSettings();
        }
コード例 #2
0
        internal ProjectConfiguration(string name, string folderPath, string description,
            string databasePath, Dictionary<string, string> propertiesMap,
            DateTime creationTime)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentException();

            if (string.IsNullOrEmpty(folderPath))
                throw new ArgumentException();

            if (string.IsNullOrEmpty(databasePath))
                throw new ArgumentException();

            _name = name;
            _folderPath = folderPath;
            _description = description;
            _creationTime = creationTime;

            // make project database path. By default it has common path with project xml file
            _databasePath = databasePath;
            _projectProperties = new ProjectProperties(propertiesMap);
            _projectArchivingSettings = new ProjectArchivingSettings(_projectProperties);
            _breaksSettings = new BreaksSettings(_projectProperties);
        }
コード例 #3
0
 public override Task <string> OnGetUnevaluatedPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties)
 {
     return(ToBooleanStringAsync(unevaluatedPropertyValue));
 }
コード例 #4
0
            private async Task <bool> TrySetPropertyAsync(string unevaluatedPropertyValue, IProjectProperties defaultProperties, ProjectRootElement projectXml)
            {
                var currentValue = await defaultProperties.GetUnevaluatedPropertyValueAsync(BuildEvent).ConfigureAwait(true);

                if (currentValue == null)
                {
                    return(false);
                }

                if (OnlyWhitespaceCharacters(unevaluatedPropertyValue))
                {
                    await defaultProperties.DeletePropertyAsync(BuildEvent).ConfigureAwait(true);

                    return(true);
                }

                await defaultProperties.SetPropertyValueAsync(BuildEvent, unevaluatedPropertyValue).ConfigureAwait(true);

                return(true);
            }
コード例 #5
0
        public override async Task <string?> OnSetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string>?dimensionalConditions = null)
        {
            ComplexTargetFramework storedProperties = await GetStoredPropertiesAsync();

            if (storedProperties.TargetFrameworkMoniker != null)
            {
                // Changing the Target Framework Moniker
                if (StringComparers.PropertyLiteralValues.Equals(propertyName, InterceptedTargetFrameworkProperty))
                {
                    // Delete stored platform properties
                    storedProperties.TargetPlatformIdentifier = null;
                    storedProperties.TargetPlatformVersion    = null;
                    await ResetPlatformPropertiesAsync(defaultProperties);

                    storedProperties.TargetFrameworkMoniker = unevaluatedPropertyValue;
                }

                // Changing the Target Platform Identifier
                else if (StringComparers.PropertyLiteralValues.Equals(propertyName, TargetPlatformProperty))
                {
                    if (unevaluatedPropertyValue != storedProperties.TargetPlatformIdentifier)
                    {
                        // Delete stored platform properties
                        storedProperties.TargetPlatformIdentifier = null;
                        storedProperties.TargetPlatformVersion    = null;
                        await ResetPlatformPropertiesAsync(defaultProperties);

                        storedProperties.TargetPlatformIdentifier = unevaluatedPropertyValue;
                    }
                }

                // Changing the Target Platform Version
                else if (StringComparers.PropertyLiteralValues.Equals(propertyName, TargetPlatformVersionProperty))
                {
                    storedProperties.TargetPlatformVersion = unevaluatedPropertyValue;
                }

                await defaultProperties.SetPropertyValueAsync(TargetFrameworkProperty, await ComputeValueAsync(storedProperties));
            }

            return(null);
        }
コード例 #6
0
        public override async Task <string> OnGetEvaluatedPropertyValueAsync(string propertyName, string evaluatedPropertyValue, IProjectProperties defaultProperties)
        {
            ConfigurationGeneral configuration = await _properties.GetConfigurationGeneralPropertiesAsync();

            string?targetFrameworkMoniker = (string?)await configuration.TargetFrameworkMoniker.GetValueAsync();

            if (targetFrameworkMoniker != null)
            {
                var targetFramework = new FrameworkName(targetFrameworkMoniker);

                // define MAKETARGETFRAMEWORKVERSION(maj, min, rev) (TARGETFRAMEWORKVERSION)((maj) << 16 | (rev) << 8 | (min))
                int  maj           = targetFramework.Version.Major;
                int  min           = targetFramework.Version.Minor;
                int  rev           = targetFramework.Version.Revision >= 0 ? targetFramework.Version.Revision : 0;
                uint propertyValue = unchecked ((uint)((maj << 16) | (rev << 8) | min));
                return(propertyValue.ToString());
            }

            return(await base.OnGetEvaluatedPropertyValueAsync(propertyName, evaluatedPropertyValue, defaultProperties));
        }
コード例 #7
0
        public override async Task <string> OnGetEvaluatedPropertyValueAsync(string evaluatedPropertyValue, IProjectProperties defaultProperties)
        {
            ConfigurationGeneral configuration = await _properties.GetConfigurationGeneralPropertiesAsync();

            string value = await configuration.OutputType.GetEvaluatedValueAtEndAsync();

            if (GetMap.TryGetValue(value, out string returnValue))
            {
                return(returnValue);
            }

            return(DefaultGetValue);
        }
コード例 #8
0
        public override async Task <string> OnSetPropertyValueAsync(string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string> dimensionalConditions = null)
        {
            var configuration = await _properties.GetConfigurationGeneralPropertiesAsync().ConfigureAwait(true);

            var currentTargetFramework = (string)await configuration.TargetFramework.GetValueAsync().ConfigureAwait(true);

            var currentTargetFrameworks = (string)await configuration.TargetFrameworks.GetValueAsync().ConfigureAwait(true);

            if (!string.IsNullOrEmpty(currentTargetFrameworks))
            {
                throw new InvalidOperationException(VSResources.MultiTFEditNotSupported);
            }
            else if (!string.IsNullOrEmpty(currentTargetFramework))
            {
                var frameworkName = new FrameworkName(unevaluatedPropertyValue);
                await defaultProperties.SetPropertyValueAsync(_targetFrameworkProperty, _frameworkParser.GetShortFrameworkName(frameworkName)).ConfigureAwait(true);
            }
            else
            {
                // CPS implements IVsHierarchy.SetProperty for the TFM property to call through the multi-targeting service and change the TFM.
                // This causes the project to be reloaded after changing the values.
                // Since the property providers are called under a write-lock, trying to reload the project on the same context fails saying it can't load the project
                // if a lock is held. We are not going to write to the file under this lock (we return null from this method) and so we fork execution here to schedule
                // a lambda on the UI thread and we don't pass the lock information from this context to the new one.
                _unconfiguredProjectVsServices.ThreadingService.Fork(() =>
                {
                    _unconfiguredProjectVsServices.VsHierarchy.SetProperty(HierarchyId.Root, (int)VsHierarchyPropID.TargetFrameworkMoniker, unevaluatedPropertyValue);
                    return(System.Threading.Tasks.Task.CompletedTask);
                }, options: ForkOptions.HideLocks | ForkOptions.StartOnMainThread,
                                                                     factory: _unconfiguredProjectVsServices.ThreadingService.JoinableTaskFactory);
            }
            return(await System.Threading.Tasks.Task.FromResult <string>(null).ConfigureAwait(false));
        }
コード例 #9
0
 public override Task <string> OnGetEvaluatedPropertyValueAsync(string propertyName, string evaluatedPropertyValue, IProjectProperties defaultProperties) =>
 GetItemIncludeValueAsync(evaluatedPropertyValue);
コード例 #10
0
        public override async Task <string> OnGetEvaluatedPropertyValueAsync(string evaluatedPropertyValue, IProjectProperties defaultProperties)
        {
            ActiveConfiguredObjects <ConfiguredProject> configuredProjects = await _projectProvider.GetActiveConfiguredProjectsAsync();

            ImmutableArray <string> .Builder builder = ImmutableArray.CreateBuilder <string>();
            foreach (ConfiguredProject configuredProject in configuredProjects.Objects)
            {
                ProjectProperties    projectProperties = configuredProject.Services.ExportProvider.GetExportedValue <ProjectProperties>();
                ConfigurationGeneral configuration     = await projectProperties.GetConfigurationGeneralPropertiesAsync();

                string currentTargetFrameworkMoniker = (string)await configuration.TargetFrameworkMoniker.GetValueAsync();

                builder.Add(currentTargetFrameworkMoniker);
            }

            return(string.Join(";", builder.ToArray()));
        }
コード例 #11
0
        public override IProjectProperties GetCommonProperties(ProjectInstance projectInstance)
        {
            IProjectProperties defaultProperties = base.GetCommonProperties(projectInstance);

            return(InterceptProperties(defaultProperties));
        }
コード例 #12
0
        public DelegatedProjectPropertiesBase(IProjectProperties properties)
        {
            Requires.NotNull(properties, nameof(properties));

            DelegatedProperties = properties;
        }
コード例 #13
0
        public override async Task <string> OnGetEvaluatedPropertyValueAsync(string evaluatedPropertyValue, IProjectProperties defaultProperties)
        {
            var command = evaluatedPropertyValue;

            // If the existing command is the empty string, then a custom command has not been set. We therefore want to return dotnet here,
            // and return exec + exe + args in the LocalDebuggerCommandArguments interceptor.
            if (command == DefaultCommand)
            {
                command = await defaultProperties.GetEvaluatedPropertyValueAsync(WindowsLocalDebugger.DotnetPathProperty).ConfigureAwait(false);
            }

            return(command);
        }
コード例 #14
0
        public override async Task <string?> OnSetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string>?dimensionalConditions = null)
        {
            await _launchSettings.SetActiveProfileAsync(unevaluatedPropertyValue);

            // We've intercepted the "set" operation and redirected it to the launch settings.
            // Return "null" to indicate that the value should _not_ be set in the project file
            // as well.
            return(null);
        }
コード例 #15
0
        public override Task <string> OnGetEvaluatedPropertyValueAsync(string propertyName, string evaluatedPropertyValue, IProjectProperties defaultProperties)
        {
            string value = evaluatedPropertyValue == "pdbonly"
                ? "full"
                : evaluatedPropertyValue;

            return(Task.FromResult(value));
        }
コード例 #16
0
        public override async Task <string> OnGetEvaluatedPropertyValueAsync(string propertyName, string evaluatedPropertyValue, IProjectProperties defaultProperties)
        {
            ActiveConfiguredObjects <ConfiguredProject>?configuredProjects = await _projectProvider.GetActiveConfiguredProjectsAsync();

            if (configuredProjects == null)
            {
                return("");
            }

            var builder = PooledArray <string> .GetInstance(capacity : configuredProjects.Objects.Length);

            foreach (ConfiguredProject configuredProject in configuredProjects.Objects)
            {
                ProjectProperties    projectProperties = configuredProject.Services.ExportProvider.GetExportedValue <ProjectProperties>();
                ConfigurationGeneral configuration     = await projectProperties.GetConfigurationGeneralPropertiesAsync();

                string?currentPlatformMoniker = (string?)await configuration.TargetPlatformIdentifier.GetValueAsync();

                string?currentPlatformVersion = (string?)await configuration.TargetPlatformVersion.GetValueAsync();

                Assumes.NotNull(currentPlatformMoniker);
                builder.Add($"{ currentPlatformMoniker }, Version={ currentPlatformVersion }");
            }

            return(string.Join(";", builder.ToArrayAndFree()));
        }
コード例 #17
0
        public override async Task <string?> OnSetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string>?dimensionalConditions = null)
        {
            if (!bool.TryParse(unevaluatedPropertyValue, out bool value))
            {
                return(null);
            }

            // When true, remove WarningsAsErrors. Otherwise, remove WarningsNotAsErrors.
            string removePropertyName  = value ? WarningsAsErrorsProperty : WarningsNotAsErrorsProperty;
            string restorePropertyName = value ? WarningsNotAsErrorsProperty : WarningsAsErrorsProperty;

            await defaultProperties.SaveValueIfCurrentlySetAsync(removePropertyName, _temporaryPropertyStorage);

            await defaultProperties.DeletePropertyAsync(removePropertyName, dimensionalConditions);

            await defaultProperties.RestoreValueIfNotCurrentlySetAsync(restorePropertyName, _temporaryPropertyStorage);

            return(await base.OnSetPropertyValueAsync(propertyName, unevaluatedPropertyValue, defaultProperties, dimensionalConditions));
        }
コード例 #18
0
        public static IProjectInstancePropertiesProvider ImplementsGetCommonProperties(IProjectProperties projectProperties = null)
        {
            var mock = new Mock <IProjectInstancePropertiesProvider>();

            mock.Setup(d => d.GetCommonProperties(It.IsAny <ProjectInstance>()))
            .Returns(() => projectProperties ?? Mock.Of <IProjectProperties>());

            return(mock.Object);
        }
コード例 #19
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);
        }
コード例 #20
0
        public override IProjectProperties GetProperties(string file, string?itemType, string?item)
        {
            IProjectProperties defaultProperties = base.GetProperties(file, itemType, item);

            return(InterceptProperties(defaultProperties));
        }
コード例 #21
0
 private async Task SetPackagePropertyValueAsync(IProjectProperties metadata, string propertyName, string propertyValue)
 {
     await metadata.SetPropertyValueAsync(
         propertyName,
         propertyValue);
 }
コード例 #22
0
 protected IProjectProperties InterceptProperties(IProjectProperties defaultProperties)
 {
     return(_interceptingValueProviders.IsDefaultOrEmpty ? defaultProperties : new InterceptedProjectProperties(_interceptingValueProviders, defaultProperties));
 }
        public override async Task <string?> OnSetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string>?dimensionalConditions = null)
        {
            if (bool.TryParse(unevaluatedPropertyValue, out bool value))
            {
                if (!value)
                {
                    await defaultProperties.DeletePropertyAsync("DocumentationFile");
                }
            }

            return(null);
        }
コード例 #24
0
        public InterceptedProjectProperties(ImmutableArray <Lazy <IInterceptingPropertyValueProvider, IInterceptingPropertyValueProviderMetadata> > valueProviders, IProjectProperties defaultProperties)
            : base(defaultProperties)
        {
            Requires.NotNullOrEmpty(valueProviders, nameof(valueProviders));

            ImmutableDictionary <string, Lazy <IInterceptingPropertyValueProvider, IInterceptingPropertyValueProviderMetadata> > .Builder builder = ImmutableDictionary.CreateBuilder <string, Lazy <IInterceptingPropertyValueProvider, IInterceptingPropertyValueProviderMetadata> >(StringComparer.OrdinalIgnoreCase);
            foreach (Lazy <IInterceptingPropertyValueProvider, IInterceptingPropertyValueProviderMetadata> valueProvider in valueProviders)
            {
                string propertyName = valueProvider.Metadata.PropertyName;

                // CONSIDER: Allow duplicate intercepting property value providers for same property name.
                Requires.Argument(!builder.ContainsKey(propertyName), nameof(valueProviders), "Duplicate property value providers for same property name");

                builder.Add(propertyName, valueProvider);
            }

            _valueProviders = builder.ToImmutable();
        }
コード例 #25
0
        public override async Task <string> OnGetUnevaluatedPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties)
        {
            ConfigurationGeneral configuration = await _properties.GetConfigurationGeneralPropertiesAsync();

            string?storedValue = await GetStoredValueAsync(configuration, propertyName);

            if (storedValue is null)
            {
                return(string.Empty);
            }

            return(storedValue);
        }
コード例 #26
0
 public override Task <string> OnGetEvaluatedPropertyValueAsync(string propertyName, string evaluatedPropertyValue, IProjectProperties defaultProperties)
 {
     return(GetPropertyValueAsync());
 }
コード例 #27
0
            public async Task <string> GetPropertyAsync(ProjectRootElement projectXml, IProjectProperties defaultProperties)
            {
                // check if value already exists
                var unevaluatedPropertyValue = await defaultProperties.GetUnevaluatedPropertyValueAsync(BuildEvent).ConfigureAwait(true);

                if (unevaluatedPropertyValue != null)
                {
                    return(unevaluatedPropertyValue);
                }

                // Check if build events can be found in targets
                return(GetFromTargets(projectXml));
            }
コード例 #28
0
        public override async Task <string?> OnSetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string>?dimensionalConditions = null)
        {
            ConfiguredProject?configuredProject = await _project.GetSuggestedConfiguredProjectAsync();

            IPropertyPagesCatalogProvider?catalogProvider = configuredProject?.Services.PropertyPagesCatalog;

            if (catalogProvider == null)
            {
                return(null);
            }

            IPropertyPagesCatalog catalog = await catalogProvider.GetCatalogAsync(PropertyPageContexts.Project);

            Rule?rule = catalog.GetSchema(unevaluatedPropertyValue);

            if (rule == null)
            {
                return(null);
            }

            if (rule.Metadata.TryGetValue("CommandName", out object pageCommandNameObj) &&
                pageCommandNameObj is string pageCommandName)
            {
                _projectThreadingService.RunAndForget(async() =>
                {
                    ILaunchSettings launchSettings = await _launchSettingsProvider.WaitForFirstSnapshot();

                    IWritableLaunchSettings writableLaunchSettings = launchSettings.ToWritableLaunchSettings();
                    IWritableLaunchProfile?activeProfile           = writableLaunchSettings.ActiveProfile;
                    if (activeProfile != null)
                    {
                        activeProfile.CommandName = pageCommandName;

                        await _launchSettingsProvider.UpdateAndSaveSettingsAsync(writableLaunchSettings.ToLaunchSettings());
                    }
                },
                                                      options: ForkOptions.HideLocks,
                                                      unconfiguredProject: _project);
            }

            return(null);
        }
コード例 #29
0
        public override async Task <string> OnGetEvaluatedPropertyValueAsync(string evaluatedPropertyValue, IProjectProperties defaultProperties)
        {
            if (!string.IsNullOrEmpty(evaluatedPropertyValue))
            {
                return(evaluatedPropertyValue);
            }

            // Default value is Version (major.minor.build components only)
            Version version = await GetDefaultVersionAsync(defaultProperties);

            return(version.ToString());
        }
コード例 #30
0
        public override async Task <string?> OnSetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string>?dimensionalConditions = null)
        {
            if (bool.TryParse(unevaluatedPropertyValue, out bool value))
            {
                if (!value)
                {
                    await defaultProperties.SaveValueIfCurrentlySetAsync(DocumentationFileMSBuildProperty, _temporaryPropertyStorage);

                    await defaultProperties.DeletePropertyAsync(DocumentationFileMSBuildProperty);
                }
                else
                {
                    await defaultProperties.RestoreValueIfNotCurrentlySetAsync(DocumentationFileMSBuildProperty, _temporaryPropertyStorage);
                }
            }

            return(null);
        }
コード例 #31
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="projectProperties"><c>ProjectProperties</c></param>
        internal BreaksSettings(IProjectProperties projectProperties)
        {
            Debug.Assert(null != projectProperties);

            _projectProperties = projectProperties;

            _InitBreaksSettings();
            DefaultBreaks.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_DefaultBreaksPropertyChanged);
        }
コード例 #32
0
 public override Task <string?> OnSetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string>?dimensionalConditions = null)
 {
     return(FromBooleanStringAsync(unevaluatedPropertyValue));
 }
コード例 #33
0
        /// <summary>
        /// Gets the application manifest property
        /// </summary>
        /// <remarks>
        /// The Application Manifest's value is one of three possibilities:
        ///     - It's either a path to file that is the manifest
        ///     - 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 (specified if it's a path) or NoWin32Manifest
        /// which is true for the second case and false or non-existent for the third.
        /// </remarks>
        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);
        }
コード例 #34
0
 public object CreatePropertiesControl(IProjectProperties project)
 {
     return new View.DiskProjectProperties { DataContext = new DiskProjectProperties(this._workspace, this._plugin, project) };
 }