コード例 #1
0
        public string GetProjectProperty(Project dteProject, string propertyName, string configuration)
        {
            if (dteProject == null)
            {
                throw new ArgumentNullException(nameof(dteProject));
            }

            if (string.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

            string                  value            = null;
            IVsHierarchy            projectHierarchy = this.GetIVsHierarchy(dteProject);
            IVsBuildPropertyStorage propertyStorage  = projectHierarchy as IVsBuildPropertyStorage;

            if (propertyStorage != null)
            {
                var hr = propertyStorage.GetPropertyValue(propertyName, configuration,
                                                          (uint)_PersistStorageType.PST_PROJECT_FILE, out value);

                // E_XML_ATTRIBUTE_NOT_FOUND is returned when the property does not exist - this is OK.
                Debug.Assert(!ErrorHandler.Succeeded(hr) || hr != E_XML_ATTRIBUTE_NOT_FOUND,
                             $"Failed to get the property '{propertyName}' for project '{dteProject.Name}'.");
            }
            else
            {
                Debug.Fail("Could not get IVsBuildPropertyStorage for EnvDTE.Project");
            }

            return(value);
        }
コード例 #2
0
        public void ClearProjectProperty(Project dteProject, string propertyName)
        {
            if (dteProject == null)
            {
                throw new ArgumentNullException(nameof(dteProject));
            }

            if (string.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

            IVsHierarchy            projectHierarchy = this.GetIVsHierarchy(dteProject);
            IVsBuildPropertyStorage propertyStorage  = projectHierarchy as IVsBuildPropertyStorage;

            if (propertyStorage != null)
            {
                var hr = propertyStorage.RemoveProperty(propertyName, string.Empty,
                                                        (uint)_PersistStorageType.PST_PROJECT_FILE);

                Debug.Assert(ErrorHandler.Succeeded(hr), $"Failed to remove property '{propertyName}' for project '{dteProject.Name}'.");
            }
            else
            {
                Debug.Fail("Could not get IVsBuildPropertyStorage for EnvDTE.Project");
            }
        }
コード例 #3
0
            public bool TrySelectFile(Project project, string title, string filter, string storageKey, out string file)
            {
                IVsSolution solution = (IVsSolution)Dialog.ServiceProvider.GetService(typeof(SVsSolution));

                IVsHierarchy hierarchy;

                if (!NativeMethods.Succeeded(solution.GetProjectOfUniqueName(project.FullName, out hierarchy)))
                {
                    file = null;
                    return(false);
                }

                // We want to read/persist the last directory location that was used if a key is provided.
                string                  lastSelectedFile = null;
                ProjectSettings         settings         = null;
                IVsBuildPropertyStorage storage          = null;

                if (storageKey != null)
                {
                    storage = hierarchy as IVsBuildPropertyStorage;
                }

                if (storage != null)
                {
                    try
                    {
                        settings         = new ProjectSettings(storage);
                        lastSelectedFile = settings[storageKey];
                    }
                    catch
                    {
                        // We don't want to fail scaffolding/selection if we have a settings issue. We'll just
                        // ignore the settings entirely.
                        settings = null;
                    }
                }

                if (ProjectItemSelector.TrySelectItem(hierarchy, title, filter, lastSelectedFile, out file))
                {
                    if (settings != null)
                    {
                        try
                        {
                            settings[storageKey] = file;
                        }
                        catch
                        {
                            // We don't want to fail scaffolding/selection if we have a settings issue. We'll just
                            // ignore the settings entirely.
                            settings = null;
                        }
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
コード例 #4
0
        /// <summary>
        /// Sets the known properties for the <see cref="ProjectItem"/> added to solution.
        /// </summary>
        /// <param name="projectItem">
        /// A <see cref="ProjectItem"/> that represents the generated item in the solution.
        /// </param>
        /// <param name="output">
        /// An <see cref="OutputFile"/> that holds metadata about the <see cref="ProjectItem"/> to be added to the solution.
        /// </param>
        private static void SetProjectItemBuildProperties(ProjectItem projectItem, OutputFile output)
        {
            if (output.BuildProperties.Count > 0)
            {
                // Get access to the build property storage service
                IServiceProvider serviceProvider = (IServiceProvider)Host;
                IVsSolution      solution        = (IVsSolution)serviceProvider.GetService(typeof(SVsSolution));
                IVsHierarchy     hierarchy;
                ErrorHandler.ThrowOnFailure(solution.GetProjectOfUniqueName(projectItem.ContainingProject.UniqueName, out hierarchy));
                IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage;
                if (buildPropertyStorage == null)
                {
                    throw new TransformationException(
                              string.Format(
                                  CultureInfo.CurrentCulture,
                                  "Project {0} does not support build properties required by {1}",
                                  projectItem.ContainingProject.Name,
                                  projectItem.Name));
                }

                // Find the target project item in the property storage
                uint projectItemId;
                ErrorHandler.ThrowOnFailure(hierarchy.ParseCanonicalName(projectItem.get_FileNames(1), out projectItemId));

                // Set build projerties for the target project item
                foreach (KeyValuePair <string, string> buildProperty in output.BuildProperties)
                {
                    ErrorHandler.ThrowOnFailure(buildPropertyStorage.SetItemAttribute(projectItemId, buildProperty.Key, buildProperty.Value));
                }
            }
        }
コード例 #5
0
        public static void SetGlobalProperty(this IVsBuildPropertyStorage propertyStorage, string propertyName, string value, string defaultValue)
        {
            if (string.IsNullOrEmpty(value) || value == defaultValue)
            {
                //propertyStorage.RemoveProperty(
                //	propertyName,
                //	string.Empty,
                //	(uint)_PersistStorageType.PST_PROJECT_FILE);

                // Removing the value never works, so it's worse to leave it empty than to serialize the
                // default value, I think.
                propertyStorage.SetPropertyValue(
                    propertyName,
                    string.Empty,
                    (uint)_PersistStorageType.PST_PROJECT_FILE,
                    defaultValue);
            }
            else
            {
                // Set the property with String.Empty condition to ensure it's global (not configuration scoped).
                propertyStorage.SetPropertyValue(
                    propertyName,
                    string.Empty,
                    (uint)_PersistStorageType.PST_PROJECT_FILE,
                    value);
            }
        }
コード例 #6
0
        /// <summary>
        /// This method should be on the UI thread. The overrides should ensure that
        /// Sets NuGetPackageImportStamp to a new random guid. This is a hack to let the project system know it is out
        /// of date.
        /// The value does not matter, it just needs to change.
        /// </summary>
        protected static void UpdateImportStamp(EnvDTEProject envDTEProject)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            IVsBuildPropertyStorage propStore = VsHierarchyUtility.ToVsHierarchy(envDTEProject) as IVsBuildPropertyStorage;

            if (propStore != null)
            {
                // <NuGetPackageImportStamp>af617720</NuGetPackageImportStamp>
                string stamp = Guid.NewGuid().ToString().Split('-')[0];
                try
                {
                    propStore.SetPropertyValue(NuGetImportStamp, string.Empty, (uint)_PersistStorageType.PST_PROJECT_FILE, stamp);
                }
                catch (Exception ex1)
                {
                    ExceptionHelper.WriteToActivityLog(ex1);
                }

                // Remove the NuGetImportStamp so that VC++ project file won't be updated with this stamp on disk,
                // which causes unnecessary source control pending changes.
                try
                {
                    propStore.RemoveProperty(NuGetImportStamp, string.Empty, (uint)_PersistStorageType.PST_PROJECT_FILE);
                }
                catch (Exception ex2)
                {
                    ExceptionHelper.WriteToActivityLog(ex2);
                }
            }
        }
コード例 #7
0
        public VsProjectFlavorCfg(VsProject project, IVsCfg baseCfg)
        {
            m_vsCfg = baseCfg;
            m_project = project;

            m_innerIVsDebuggableProjectCfg = m_vsCfg as IVsDebuggableProjectCfg;
            m_IVsBuildPropertyStorage = m_project as IVsBuildPropertyStorage;

            Debug.Assert(m_innerIVsDebuggableProjectCfg != null);

            m_connectionsDeployStatusCallback = new ConnectionPoint.Connections();

            DeployPropertyPort = new ProjectBuildProperty("DeployTransport", m_IVsBuildPropertyStorage, this, _PersistStorageType.PST_USER_FILE, _PersistStorageType.PST_PROJECT_FILE, DebugPort.NameFromPortFilter(PortFilter.Emulator));
            DeployPropertyDevice = new ProjectBuildProperty("DeployDevice", m_IVsBuildPropertyStorage, this, _PersistStorageType.PST_USER_FILE, _PersistStorageType.PST_PROJECT_FILE);

            GenerateStubsFlag = new ProjectBuildPropertyBool("MF_GenerateStubs", m_IVsBuildPropertyStorage, this, _PersistStorageType.PST_USER_FILE);
            GenerateStubsRootName = new ProjectBuildProperty("MF_GenerateStubsRootName", m_IVsBuildPropertyStorage, this, _PersistStorageType.PST_USER_FILE, _PersistStorageType.PST_PROJECT_FILE, "TARGET");
            GenerateStubsDirectory = new ProjectBuildProperty("MF_GenerateStubsDirectory", m_IVsBuildPropertyStorage, this, _PersistStorageType.PST_USER_FILE, _PersistStorageType.PST_PROJECT_FILE, "DIRECTORY");

            try
            {
                ActivateDebugEngine();
            }
            catch (Exception e)
            {
                VsPackage.MessageCentre.InternalErrorMsg(false, String.Format("Unable to register debug engine: {0}", e.Message));
            }
        }
コード例 #8
0
        public static void SetProjectProperty(IVsSolution solution, Project project, string propertyName, string propertyValue, string configName, _PersistStorageType persistStorageType)
        {
            IVsHierarchy            hierarchy            = GetHierarchy(solution, project);
            IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage;

            buildPropertyStorage.SetPropertyValue(propertyName, configName, (uint)persistStorageType, propertyValue);
        }
コード例 #9
0
 public GlobalProjectProperties(ProjectNode project)
 {
     msBuildProject = project.As <Project>();
     dteProject     = project.As <EnvDTE.Project>();
     vsBuild        = project.HierarchyNode.VsHierarchy as IVsBuildPropertyStorage;
     accessor       = new DynamicPropertyAccessor(this);
 }
コード例 #10
0
 public PropertyExtender(IVsBuildPropertyStorage storage, uint itemId, IExtenderSite extenderSite, int cookie)
 {
     _storage      = storage;
     _itemId       = itemId;
     _extenderSite = extenderSite;
     _cookie       = cookie;
 }
コード例 #11
0
        public VsProjectFlavorCfg(VsProject project, IVsCfg baseCfg)
        {
            m_vsCfg   = baseCfg;
            m_project = project;

            m_innerIVsDebuggableProjectCfg = m_vsCfg as IVsDebuggableProjectCfg;
            m_IVsBuildPropertyStorage      = m_project as IVsBuildPropertyStorage;

            Debug.Assert(m_innerIVsDebuggableProjectCfg != null);

            m_connectionsDeployStatusCallback = new ConnectionPoint.Connections();

            DeployPropertyPort   = new ProjectBuildProperty("DeployTransport", m_IVsBuildPropertyStorage, this, _PersistStorageType.PST_USER_FILE, _PersistStorageType.PST_PROJECT_FILE, DebugPort.NameFromPortFilter(PortFilter.Emulator));
            DeployPropertyDevice = new ProjectBuildProperty("DeployDevice", m_IVsBuildPropertyStorage, this, _PersistStorageType.PST_USER_FILE, _PersistStorageType.PST_PROJECT_FILE);

            GenerateStubsFlag      = new ProjectBuildPropertyBool("MF_GenerateStubs", m_IVsBuildPropertyStorage, this, _PersistStorageType.PST_USER_FILE);
            GenerateStubsRootName  = new ProjectBuildProperty("MF_GenerateStubsRootName", m_IVsBuildPropertyStorage, this, _PersistStorageType.PST_USER_FILE, _PersistStorageType.PST_PROJECT_FILE, "TARGET");
            GenerateStubsDirectory = new ProjectBuildProperty("MF_GenerateStubsDirectory", m_IVsBuildPropertyStorage, this, _PersistStorageType.PST_USER_FILE, _PersistStorageType.PST_PROJECT_FILE, "DIRECTORY");

            try
            {
                ActivateDebugEngine();
            }
            catch (Exception e)
            {
                VsPackage.MessageCentre.InternalErrorMsg(false, String.Format("Unable to register debug engine: {0}", e.Message));
            }
        }
コード例 #12
0
        private static void GetBuildPropertyStorage(ProjectItem projectItem, out IVsBuildPropertyStorage propertyStorage, out uint projectItemId)
        {
            IVsHierarchy hierarchy = projectItem.ContainingProject.AsHierarchy();

            propertyStorage = (IVsBuildPropertyStorage)hierarchy;
            ErrorHandler.ThrowOnFailure(hierarchy.ParseCanonicalName(projectItem.FileNames[1], out projectItemId));
        }
コード例 #13
0
        public GrammarFileObjectExtenderProperties(IVsBuildPropertyStorage buildPropertyStorage, uint itemId)
        {
            Contract.Requires <ArgumentNullException>(buildPropertyStorage != null, "buildPropertyStorage");

            _buildPropertyStorage = buildPropertyStorage;
            _itemId = itemId;
        }
コード例 #14
0
        /// <summary>
        /// Creates a new transformation file and adds it to the project.
        /// </summary>
        /// <param name="selectedProjectItem">The selected item to be transformed</param>
        /// <param name="itemName">Full name of the transformation file</param>
        /// <param name="projectPath">Full path to the current project</param>
        /// <param name="addDependentUpon">Wheter to add the new file dependent upon the source file</param>
        private void AddTransformFile(ProjectItem selectedProjectItem, string itemName, string projectPath, bool addDependentUpon)
        {
            try
            {
                string transformPath  = Path.Combine(projectPath, itemName);
                string sourceFileName = selectedProjectItem.FileNames[1];

                ITransformer transformer = TransformerFactory.GetTransformer(sourceFileName, null);

                transformer.CreateTransformFile(sourceFileName, transformPath, false);

                // Add the file to the project
                // If the DependentUpon metadata is required, add it under the original file
                // If not, add it to the project
                ProjectItem addedItem = addDependentUpon ? selectedProjectItem.ProjectItems.AddFromFile(transformPath)
                                                      : selectedProjectItem.ContainingProject.ProjectItems.AddFromFile(transformPath);

                // We need to set the Build Action to None to ensure that it doesn't get published for web projects
                addedItem.Properties.Item("ItemType").Value = "None";

                IVsHierarchy            hierarchy            = null;
                IVsProject              vsProject            = (IVsProject)hierarchy;
                IVsBuildPropertyStorage buildPropertyStorage = vsProject as IVsBuildPropertyStorage;
                if (buildPropertyStorage == null)
                {
                    this.logger.LogMessage("Error obtaining IVsBuildPropertyStorage from hierarcy.");
                }
            }
            catch (Exception ex)
            {
                this.logger.LogMessage("AddTransformFile: Exception> " + ex.Message);
            }
        }
コード例 #15
0
ファイル: GlobalProjectProperties.cs プロジェクト: kzu/clide
		public GlobalProjectProperties(ProjectNode project)
		{
			msBuildProject = project.As<Project>();
			dteProject = project.As<EnvDTE.Project>();
			vsBuild = project.HierarchyNode.HierarchyIdentity.Hierarchy as IVsBuildPropertyStorage;
			accessor = new DynamicPropertyAccessor(this);
		}
コード例 #16
0
        public GrammarFileObjectExtenderProperties([NotNull] IVsBuildPropertyStorage buildPropertyStorage, uint itemId)
        {
            Requires.NotNull(buildPropertyStorage, nameof(buildPropertyStorage));

            _buildPropertyStorage = buildPropertyStorage;
            _itemId = itemId;
        }
コード例 #17
0
        /// <summary>
        /// Initializes a new instance of the BuildIntegrationOptions class.
        /// </summary>
        /// <param name="project">The VS project.</param>
        public BuildIntegrationOptions(IVsBuildPropertyStorage project)
        {
            Param.RequireNotNull(project, "project");

            this.project = project;
            this.InitializeComponent();
        }
コード例 #18
0
        public void ConfigProperties()
        {
            using (PackageTestEnvironment testEnv = new PackageTestEnvironment())
            {
                IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage;
                Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage.");

                // Get (2 different configs)
                string propertyName = "ConfigProperty";
                string value        = null;
                int    hr           = buildProperty.GetPropertyValue(propertyName, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out value);
                Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed");
                Assert.AreEqual("DebugValue", value);
                hr = buildProperty.GetPropertyValue(propertyName, "Release", (uint)_PersistStorageType.PST_PROJECT_FILE, out value);
                Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed");
                Assert.AreEqual("ReleaseValue", value);

                // Set (with get to confirm)
                string newValue = "UpdatedConfig";
                hr = buildProperty.SetPropertyValue(propertyName, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, newValue);
                Assert.AreEqual <int>(VSConstants.S_OK, hr, "SetPropertyValue failed");
                hr = buildProperty.GetPropertyValue(propertyName, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out value);
                Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed");
                Assert.AreEqual(newValue, value);
            }
        }
コード例 #19
0
        /// <summary>
        /// Verifies if the item has a trasform configured already
        /// </summary>
        /// <param name="vsProject">The current project</param>
        /// <param name="itemid">The id of the selected item inside the project</param>
        /// <returns>True if the item has a transform</returns>
        private bool IsItemTransformItem(IVsProject vsProject, uint itemid)
        {
            IVsBuildPropertyStorage buildPropertyStorage = vsProject as IVsBuildPropertyStorage;

            if (buildPropertyStorage == null)
            {
                this.LogMessageWriteLineFormat("Error obtaining IVsBuildPropertyStorage from hierarcy.");
                return(false);
            }

            string value;

            buildPropertyStorage.GetItemAttribute(itemid, IsTransformFile, out value);
            bool valueAsBool;

            if (bool.TryParse(value, out valueAsBool) && valueAsBool)
            {
                return(true);
            }

            // we need to special case web.config transform files
            string filePath;

            buildPropertyStorage.GetItemAttribute(itemid, "FullPath", out filePath);
            IEnumerable <string> configs = ProjectUtilities.GetProjectConfigurations(vsProject as IVsHierarchy);

            // If the project is a web app, check for the Web.config files added by default
            return(ProjectUtilities.IsProjectWebApp(vsProject) && PackageUtilities.IsFileTransform("web.config", Path.GetFileName(filePath), configs));
        }
コード例 #20
0
        /// <summary>
        /// Creates a new XML transformation file and adds it to the project.
        /// </summary>
        /// <param name="selectedProjectItem">The selected item to be transformed</param>
        /// <param name="content">Contents to be written to the transformation file</param>
        /// <param name="itemName">Full name of the transformation file</param>
        /// <param name="projectPath">Full path to the current project</param>
        private void AddXdtTransformFile(ProjectItem selectedProjectItem, string content, string itemName, string projectPath)
        {
            try
            {
                string itemPath = Path.Combine(projectPath, itemName);
                if (!File.Exists(itemPath))
                {
                    // create the new XDT file
                    using (StreamWriter writer = new StreamWriter(itemPath))
                    {
                        writer.Write(content);
                    }
                }

                // and add it to the project
                ProjectItem addedItem = selectedProjectItem.ProjectItems.AddFromFile(itemPath);

                // we need to set the Build Action to None to ensure that it doesn't get published for web projects
                addedItem.Properties.Item("ItemType").Value = "None";

                IVsHierarchy            hierarchy            = null;
                IVsProject              vsProject            = (IVsProject)hierarchy;
                IVsBuildPropertyStorage buildPropertyStorage = vsProject as IVsBuildPropertyStorage;
                if (buildPropertyStorage == null)
                {
                    this.LogMessageWriteLineFormat("Error obtaining IVsBuildPropertyStorage from hierarcy.");
                }
            }
            catch (Exception ex)
            {
                this.LogMessageWriteLineFormat("AddTransformFile: Exception> " + ex.Message);
            }
        }
コード例 #21
0
        void SetBuildProperties(string inputFileName, ProjectItem item)
        {
            Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
            {
                string uniqueName = item.ContainingProject.UniqueName;

                IVsSolution solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution));

                IVsHierarchy hierarchy;
                solution.GetProjectOfUniqueName(uniqueName, out hierarchy);

                IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage;

                if (buildPropertyStorage != null)
                {
                    string fullPath = Path.ChangeExtension(inputFileName, GetDefaultExtension());

                    uint itemId;
                    hierarchy.ParseCanonicalName(fullPath, out itemId);

                    buildPropertyStorage.SetItemAttribute(itemId, "MergeWithCTO", "true");
                    buildPropertyStorage.SetItemAttribute(itemId, "ManifestResourceName", "VSPackage");
                }
            }), DispatcherPriority.ApplicationIdle, null);
        }
コード例 #22
0
        /// <summary>
        /// Initializes a new instance of the BuildIntegrationOptions class.
        /// </summary>
        /// <param name="project">The VS project.</param>
        public BuildIntegrationOptions(IVsBuildPropertyStorage project)
        {
            Param.RequireNotNull(project, "project");

            this.project = project;
            this.InitializeComponent();
        }
コード例 #23
0
        public void TestGlobalPropertyMatch()
        {
            UIThreadInvoker.Invoke((ThreadInvoker) delegate()
            {
                //Get the global service provider and the dte
                IServiceProvider sp = VsIdeTestHostContext.ServiceProvider;
                DTE dte             = (DTE)sp.GetService(typeof(DTE));

                string destination  = Path.Combine(TestContext.TestDir, TestContext.TestName);
                ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                Microsoft.Build.BuildEngine.Project buildProject = typeof(ProjectNode).GetProperty("BuildProject", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(project, new object[] { }) as Microsoft.Build.BuildEngine.Project;
                IVsHierarchy nestedProject = Utilities.GetNestedHierarchy(project, "ANestedProject");

                IVsBuildPropertyStorage nestedProjectPropertyStorage = nestedProject as IVsBuildPropertyStorage;
                foreach (string property in Enum.GetNames(typeof(GlobalProperty)))
                {
                    string nestedProjectGlobalProperty;

                    // We will pass in the debug configuration since the GetPropertyValue will change the global property to whatever does not exist as configuration like empty or null.
                    nestedProjectPropertyStorage.GetPropertyValue(property, "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out nestedProjectGlobalProperty);

                    string parentProjectGlobalProperty = buildProject.GlobalProperties[property].Value;

                    bool result;
                    bool isBoolean = (Boolean.TryParse(parentProjectGlobalProperty, out result) == true);
                    Assert.IsTrue(String.Compare(nestedProjectGlobalProperty, parentProjectGlobalProperty, isBoolean ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0, "The following global Properties do not match for Property: " + property + " Nested :" + nestedProjectGlobalProperty + " Parent:" + parentProjectGlobalProperty);
                }
            });
        }
コード例 #24
0
 public PropertyExtender(IVsBuildPropertyStorage storage, uint itemId, IExtenderSite extenderSite, int cookie)
 {
     this.storage      = storage;
     this.itemId       = itemId;
     this.extenderSite = extenderSite;
     this.cookie       = cookie;
 }
コード例 #25
0
 public NoneItemExtender(IVsHierarchy hierarchy, uint item, IExtenderSite site, int cookie)
 {
     propertyStorage = (IVsBuildPropertyStorage)hierarchy;
     this.item       = item;
     this.site       = site;
     this.cookie     = cookie;
 }
コード例 #26
0
        public GrammarFileObjectExtenderProperties(IVsBuildPropertyStorage buildPropertyStorage, uint itemId)
        {
            Contract.Requires<ArgumentNullException>(buildPropertyStorage != null, "buildPropertyStorage");

            _buildPropertyStorage = buildPropertyStorage;
            _itemId = itemId;
        }
コード例 #27
0
        public void GlobalProperties()
        {
            using (PackageTestEnvironment testEnv = new PackageTestEnvironment())
            {
                IVsBuildPropertyStorage buildProperty = testEnv.Project as IVsBuildPropertyStorage;
                Assert.IsNotNull(buildProperty, "Project does not implements IVsBuildPropertyStorage.");

                // Get
                string propertyName = "GlobalProperty";
                string value        = null;
                int    hr           = buildProperty.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value);
                Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed");
                Assert.AreEqual("Global", value);

                // Set (with get to confirm)
                string newValue = "UpdatedGlobal";
                hr = buildProperty.SetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, newValue);
                Assert.AreEqual <int>(VSConstants.S_OK, hr, "SetPropertyValue failed");
                hr = buildProperty.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value);
                Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed");
                Assert.AreEqual(newValue, value);

                // Remove (with get to confirm)
                hr = buildProperty.RemoveProperty(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE);
                Assert.AreEqual <int>(VSConstants.S_OK, hr, "RemoveProperty failed");
                hr = buildProperty.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value);
                Assert.AreEqual <int>(VSConstants.S_OK, hr, "GetPropertyValue failed");
                Assert.AreEqual(String.Empty, value);
            }
        }
コード例 #28
0
        /// <summary>
        /// Deletes a property from the project's .user file.
        /// </summary>
        /// <param name="project">The project to delete the property from.</param>
        /// <param name="propertyName">The name of the property to delete.</param>
        public void DeleteUserProperty(Project project, string propertyName)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            IVsBuildPropertyStorage propertyStore = GetProjectPropertyStore(project);

            ErrorHandler.ThrowOnFailure(
                propertyStore.RemoveProperty(propertyName, null, UserFileFlag));
        }
コード例 #29
0
        void IVsProjectCfgDebugTargetSelection.GetCurrentDebugTarget(out Guid pguidDebugTargetType, out uint pDebugTargetTypeId, out string pbstrCurrentDebugTarget)
        {
            IVsBuildPropertyStorage bps = this;

            pguidDebugTargetType    = VSConstants.AppPackageDebugTargets.guidAppPackageDebugTargetCmdSet;
            pDebugTargetTypeId      = VSConstants.AppPackageDebugTargets.cmdidAppPackage_RemoteMachine;
            pbstrCurrentDebugTarget = RemoteTarget;
        }
コード例 #30
0
        protected override void OnRun(DebuggerStartInfo startInfo)
        {
            base.OnRun(startInfo);
            UseOperationThread = true;
            Project startupProject = ((Mono.Debugging.VisualStudio.StartInfo)startInfo).StartupProject;

            IVsHierarchy         hierarchy = startupProject.ToHierarchy();
            IProjectNode         node      = startupProject.AsProjectNode();
            BuildPropertyStorage storage   = new BuildPropertyStorage(hierarchy, node.Configuration.ActiveConfigurationName);

            var enableAotMode   = storage.GetPropertyValue <bool>(XamarinWindowsConstants.EnableAotModeProperty);
            var bundleAsemblies = storage.GetPropertyValue <bool>(XamarinWindowsConstants.BundleAssembliesProperty);
            var generateDebuggableAotModules = storage.GetPropertyValue <bool>(XamarinWindowsConstants.GenerateDebuggableAotModulesProperty);
            var additionalMonoOptions        = storage.GetPropertyValue <string>(XamarinWindowsConstants.AdditionalMonoOptionsProperty)?.Trim();
            var monoLogLevel = storage.GetPropertyValue <string>(XamarinWindowsConstants.MonoLogLevelProperty);
            var monoLogMask  = storage.GetPropertyValue <string>(XamarinWindowsConstants.MonoLogMaskProperty);

            var startArguments = startupProject.ConfigurationManager.ActiveConfiguration.Properties.Item("StartArguments").Value.ToString();
            var assemblyPath   = GetOutputAssembly(startupProject, enableAotMode, generateDebuggableAotModules);
            var monoDirectory  = Path.Combine(GetInstallPath(), @"MSBuild\Xamarin\Windows\x64\Release");
            var monoPath       = Path.Combine(GetInstallPath(), @"Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.Windows\v1.0");
            var args           = ((Mono.Debugging.VisualStudio.StartInfo)startInfo).StartArgs as SoftDebuggerListenArgs;

            process = new System.Diagnostics.Process();
            var workingDirectory = Path.GetDirectoryName(assemblyPath);
            var monoOptions      = $"--debug --debugger-agent=transport=dt_socket,address=127.0.0.1:{args.DebugPort}";

            if (!string.IsNullOrEmpty(additionalMonoOptions))
            {
                monoOptions += " " + additionalMonoOptions;
            }

            if (!enableAotMode)
            {
                process.StartInfo = new ProcessStartInfo(Path.Combine(monoDirectory, "mono-sgen.exe"), monoOptions + $" \"{assemblyPath}\" {startArguments}".TrimEnd());
            }
            else
            {
                IVsBuildPropertyStorage buildPropertyStorage = (IVsBuildPropertyStorage)hierarchy;
                string nativeProjectName = buildPropertyStorage.GetMSBuildPropertyValue("_XWNativeProjectName", null);
                var    launcherExe       = Path.Combine(workingDirectory, nativeProjectName + ".exe");
                process.StartInfo = new ProcessStartInfo(launcherExe, startArguments);
                process.StartInfo.EnvironmentVariables["MONO_BUNDLED_OPTIONS"] = monoOptions;
            }
            process.StartInfo.WorkingDirectory = workingDirectory;
            process.StartInfo.UseShellExecute  = false;
            if (!string.IsNullOrEmpty(monoLogLevel))
            {
                process.StartInfo.EnvironmentVariables["MONO_LOG_LEVEL"] = monoLogLevel;
            }
            if (!string.IsNullOrEmpty(monoLogMask))
            {
                process.StartInfo.EnvironmentVariables["MONO_LOG_MASK"] = monoLogMask;
            }

            process.StartInfo.EnvironmentVariables["MONO_PATH"] = monoPath;
            process.Start();
        }
コード例 #31
0
        public ProjectPropertyStorage(IVsBuildPropertyStorage storage)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            _storage = storage;
        }
コード例 #32
0
        public AssemblyReferenceExtender(EnvDTE.IExtenderSite extenderSite, int cookie, VSLangProj.Reference reference, IVsBuildPropertyStorage storage, uint itemId)
        {
            _extenderSite = extenderSite;
            _cookie       = cookie;
            _storage      = storage;
            _itemid       = itemId;

            Reference = reference;
        }
コード例 #33
0
 public ItemProperties(ItemNode item)
 {
     this.node = item.HierarchyNode;
     this.item = item.HierarchyNode.ExtensibilityObject as ProjectItem;
     this.msBuild = item.HierarchyNode.VsHierarchy as IVsBuildPropertyStorage;
     if (System.Diagnostics.Debugger.IsAttached)
         debugString = string.Join(Environment.NewLine, GetDynamicMemberNames()
             .Select(name => name + "=" + GetValue(name)));
 }
コード例 #34
0
        int IVsBuildPropertyStorage.SetPropertyValue(string propertyName, string configName, uint storage, string propertyValue)
        {
            IVsBuildPropertyStorage cfg = _innerCfg as IVsBuildPropertyStorage;

            if (cfg != null)
            {
                return(cfg.SetPropertyValue(propertyName, configName, storage, propertyValue));
            }
            return(VSConstants.S_OK);
        }
コード例 #35
0
        public static void SetProjectItemProperty(IVsSolution solution, ProjectItem projectItem, string propertyName, string propertyValue)
        {
            IVsHierarchy            hierarchy            = GetHierarchy(solution, projectItem.ContainingProject);
            IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage;
            uint   itemId;
            string fullPath = (string)projectItem.Properties.Item("FullPath").Value;

            hierarchy.ParseCanonicalName(fullPath, out itemId);
            buildPropertyStorage.SetItemAttribute(itemId, propertyName, propertyValue);
        }
コード例 #36
0
ファイル: ConfigProjectProperties.cs プロジェクト: kzu/clide
		public ConfigProjectProperties(ProjectNode project, string configName)
		{
			this.project = project;
			this.configName = configName;
			vsBuild = project.HierarchyNode.HierarchyIdentity.Hierarchy as IVsBuildPropertyStorage;
			if (vsBuild == null)
				tracer.Warn(Strings.ConfigProjectProperties.NonMsBuildProject(project.Text));

			accessor = new DynamicPropertyAccessor(this);
		}
コード例 #37
0
		public UserProjectProperties(ProjectNode project)
		{
			this.project = project;
			msBuildProject = project.As<Project>();
			dteProject = project.As<EnvDTE.Project>();
			vsBuild = project.HierarchyNode.VsHierarchy as IVsBuildPropertyStorage;

			if (msBuildProject == null || vsBuild == null)
				tracer.Warn(Strings.UserProjectProperties.NonMsBuildProject(project.DisplayName));

			accessor = new DynamicPropertyAccessor(this);
		}
コード例 #38
0
        internal BrowseObjectExtender(IServiceProvider serviceProvider, IVsBrowseObject browseObject, IExtenderSite site, int cookie)
        {
            Debug.Assert(serviceProvider != null, "serviceProvider");
            Debug.Assert(browseObject != null, "browseObject");
            Debug.Assert(site != null, "site");
            Debug.Assert(cookie != 0, "cookie");

            this.site = site;
            this.cookie = cookie;
            this.serviceProvider = serviceProvider;
            ErrorHandler.ThrowOnFailure(browseObject.GetProjectItem(out this.hierarchy, out this.itemId));
            this.propertyStorage = (IVsBuildPropertyStorage)this.hierarchy;
            this.CustomToolParameters = new CustomToolParameters(this.serviceProvider, this.hierarchy, this.itemId);
        }
コード例 #39
0
        /// <summary>
        /// Use the data passed in to initialize ourselve
        /// </summary>
        /// <param name="dataObject">This is normally our configuration object or null when we should release it</param>
        public void Initialize(object[] dataObjects)
        {
            // If we are editing multiple configuration at once, we may get multiple objects
            foreach (object dataObject in dataObjects)
            {
                var browseObject = dataObject as IVsBrowseObject;

                if (browseObject != null)
                {
                    IVsHierarchy hierarchy;
                    uint item;

                    browseObject.GetProjectItem(out hierarchy, out item);
                    buildStorage = (IVsBuildPropertyStorage)hierarchy;
                }
            }
        }
コード例 #40
0
 private static void GetBuildPropertyStorage(ProjectItem projectItem, out IVsBuildPropertyStorage propertyStorage, out uint projectItemId)
 {
     IVsHierarchy hierarchy = projectItem.ContainingProject.AsHierarchy();
     propertyStorage = (IVsBuildPropertyStorage)hierarchy;
     ErrorHandler.ThrowOnFailure(hierarchy.ParseCanonicalName(projectItem.FileNames[1], out projectItemId));
 }
コード例 #41
0
 public ProjectBuildProperty(string propName, IVsBuildPropertyStorage storage, VsProjectFlavorCfg cfg, _PersistStorageType type, _PersistStorageType typeDefault, string valDefault)
 {
     m_propName = propName;
     m_storage = storage;
     m_cfg = cfg;
     m_type = type;
     m_fPropertyLoaded = false;
     m_valDefault = valDefault;
     m_typeDefault = typeDefault;
 }
コード例 #42
0
        private bool ValidateSlowCheetahTargetsAvailable(IVsBuildPropertyStorage buildPropertyStorage, string projectFullPath, string importPath, out bool addImports)
        {
            addImports = false;

            string importsExpression = string.Format("$({0})",Settings.Default.SlowCheetahTargets);
#if USE_SLOWCHEETAH_TARGET_PROPERTY_FOR_IMPORT
            if (!IsSlowCheetahImported(buildPropertyStorage)) {
#else
            if (IsSlowCheetahImported(projectFullPath, importsExpression)) {
#endif
                return true;
            }

            if (HasUserAcceptedWarningMessage(projectFullPath, importPath)) {
                addImports = true;
                return true;
            }

            return false;
        }

        /// <summary>
        /// Checks the project file to see if the appropriate import has been made to slow Cheetah.
        /// </summary>
        /// <param name="buildPropertyStorage">Project's build property storage interface.</param>
        /// <returns>True if the SlowCheetah import is in the project file; otherwise false.</returns>
#if USE_SLOWCHEETAH_TARGET_PROPERTY_FOR_IMPORT
        private bool IsSlowCheetahImported(IVsBuildPropertyStorage buildPropertyStorage)
        {
            // check to see if the SlowCheetahImport property is set to true by the import file
            string propertyValue;
            buildPropertyStorage.GetPropertyValue(Resources.String_SlowCheetahImportProp, "|", (uint) _PersistStorageType.PST_PROJECT_FILE, out propertyValue);
            if (!string.IsNullOrWhiteSpace(propertyValue)) {
                // this property is assigned the value of $(MSBuildThisFileFullPath), which sets it to the import path of the SlowCheetah targets file
                // this is to make checking of the import fast and efficient, since this is not currently supported by VS
                return true;
            }

            return false;
        }
コード例 #43
0
        protected override void SetInnerProject(IntPtr innerIUnknown)
        {
            // 
            // This was changed to support VS2012 - The FlavoredProject base class we were using
            // was throwing a COM exception, so we switched to use the newer FlavoredProjectBase class
            // which uses an IntPtr instead of a managed object for this class.  The following method
            // converts the IUnknown IntPtr into a managed object from which we can convert into the 
            // following interfaces.
            //
            object inner = Marshal.GetUniqueObjectForIUnknown(innerIUnknown);

            m_innerIVsProject = inner as IVsProject;
            m_innerIVsProjectBuildSystem = inner as IVsProjectBuildSystem;
            m_innerIVsHierarchy = inner as IVsHierarchy;
            m_innerIVsUIHierarchy = inner as IVsUIHierarchy;
            m_innerSingleFileGeneratorFactory = inner as IVsSingleFileGeneratorFactory;
            m_innerIVsBuildPropertyStorage = inner as IVsBuildPropertyStorage;
            m_innerProjectSpecialFiles = inner as IVsProjectSpecialFiles;

            Debug.Assert(m_innerIVsProject                 != null);
            Debug.Assert(m_innerIVsProjectBuildSystem      != null);
            Debug.Assert(m_innerIVsHierarchy               != null);
            Debug.Assert(m_innerIVsUIHierarchy             != null);
            Debug.Assert(m_innerSingleFileGeneratorFactory != null);
            Debug.Assert(m_innerIVsBuildPropertyStorage    != null);
            Debug.Assert(m_innerProjectSpecialFiles        != null);

            if (this.serviceProvider == null)
            {
                this.serviceProvider = (System.IServiceProvider)this.m_package;
            }

            base.SetInnerProject(innerIUnknown);
        }
コード例 #44
0
 public ProjectBuildProperty(string propName, IVsBuildPropertyStorage storage, VsProjectFlavorCfg cfg, _PersistStorageType type)
     : this(propName, storage, cfg, type, PersistStorageTypeNone, string.Empty)
 {
 }
コード例 #45
0
 public ProjectBuildPropertyBool(string propName, IVsBuildPropertyStorage storage, VsProjectFlavorCfg cfg, _PersistStorageType type) : base (propName, storage, cfg, type)
 {
 }
コード例 #46
0
 internal void GetProjectItem(out IVsBuildPropertyStorage project, out uint itemId)
 {
     project = (IVsBuildPropertyStorage)this.project;
     itemId = this.projectItemId;
 }
コード例 #47
0
 public ProjectProperties(ProjectNode project)
 {
     dteProject = project.m_dteProject;
      vsBuild = project.HierarchyNode.VsHierarchy as IVsBuildPropertyStorage;
 }
コード例 #48
0
ファイル: ProjectSettings.cs プロジェクト: haxard/lab
        public ProjectSettings(IVsBuildPropertyStorage storage)
        {
            Contract.Assert(storage != null);

            Storage = storage;
        }
コード例 #49
0
        private static void GetProjectItem(object component, out IVsBuildPropertyStorage project, out uint itemId)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            var parent = component as CustomToolParameters;
            if (parent == null)
            {
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        "Object of type {0} is expected, actual object is of type {1}.",
                        typeof(CustomToolParameters).FullName,
                        component.GetType().FullName),
                    "component");
            }

            parent.GetProjectItem(out project, out itemId);            
        }
コード例 #50
0
ファイル: ItemProperties.cs プロジェクト: kzu/clide
		public ItemProperties (ItemNode item)
		{
			this.item = item.HierarchyNode.GetExtenderObject () as ProjectItem;
			node = item.HierarchyNode;
			msBuild = item.HierarchyNode.GetRoot ().HierarchyIdentity.Hierarchy as IVsBuildPropertyStorage;
		}
コード例 #51
0
ファイル: PropertyPage.cs プロジェクト: hesam/SketchSharp
    private void SetBuildStorage()
    {
      // Get the build storage associated with this property page.
      buildStorage = null;
      if (configs != null) {
        foreach (object config in configs) {
          if (config != null) {
            // try to retrieve the project using IVs(Cfg)BrowseObject
            IVsHierarchy project = null;
            IVsBrowseObject browse = config as IVsBrowseObject;
            if (browse != null) {
              uint itemid;
              browse.GetProjectItem(out project, out itemid);
            }
            else {
              IVsCfgBrowseObject cfgBrowse = config as IVsCfgBrowseObject;
              if (cfgBrowse != null) {
                uint itemid;
                cfgBrowse.GetProjectItem(out project, out itemid);
              }
            }

            // try to cast the project to a buildstorage
            buildStorage = project as IVsBuildPropertyStorage;
            if (buildStorage != null) {
              return;  // we are done.
            }
          }
        }
      }
    }
コード例 #52
0
ファイル: PropertyPage.cs プロジェクト: hesam/SketchSharp
 public void SetObjects(uint cObjects, object[] ppunk)
 {
   configs = null;
   configNames = null;
   buildStorage = null;
   if (pane != null && ppunk != null) {
     configs = ppunk;
     SetBuildStorage();
     SetConfigurationNames();
     initializing = true;
      pane.LoadProperties(configNames, this);
     initializing = false;
     SetDirty(false);
   }
 }