How to obtain reference to IVsBrowseObjectContext from VSPackage?

 
I've developed small extension that modifies content of csproj files. I follow standard pattern to get the Project object:
var dte = GetGlobalService(typeof(DTE)) as DTE2
var selectedProjects = (Array)dte.ActiveSolutionProjects;
var project = (Project)selectedProjects.GetValue(0);
However Project interface is not sufficient for my purposes (checking items metadata, reinserting items) and I had to fallback to using MSBuild's Project class like this:
var msBuildProject = new Microsoft.Build.Evaluation.Project(project.FullName);
ModifyProjectsContent(msBuildProject);
msBuildProject.Save();
ProjectCollection
.GlobalProjectCollection
.UnloadProject(msBuildProject);
This chunk of code is executed whenever an item is added/renamed/removed to the project.
This works fine however there is caveat - VS detects that file has been changed and prompts to reload project which bad because I want it to happen silently. This approach also does not play well with batch modifications or source control tools. And finally
it is just ugly.
So I decided to check how others are doing it, in particular how does nuget adds its properties. I found out that it uses UncofiguredProject object that retrieve MSBuildProject as following:
var project = .....
var solution = GetGlobalService(typeof(IVsSolution)) as IVsSolution;
IVsHierarchy hierarchy;
solution.GetProjectOfUniqueName(project.GetUniqueName(), out hierarchy);
var context = project as IVsBrowseObjectContext;
if (context == null)
var hierarchy2 = project as IVsHierarchy;
object extObject;
hierarchy2.GetProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ExtObject, out extObject))
Project dteProject = extObject as Project;
context = dteProject.Object as IVsBrowseObjectContext;
var unconfiguredProject = context.UnconfiguredProject : null;
After unconfigureProject is obtained reference to msbuild project obtained like following:
var service = unconfiguredProject.ProjectService.Services.ProjectLockService;
using (var x = await service.WriteLockAsync())
await x.CheckoutAsync(unconfiguredProject.FullPath);
ConfiguredProject configuredProject = await unconfiguredProject.GetSuggestedConfiguredProjectAsync();
var buildProject = await x.GetProjectAsync(configuredProject);
// can modify buildProject here
await x.ReleaseAsync();
await Task.Run(() =>
unconfiguredProject.ProjectService.Services.ThreadingPolicy.SwitchToUIThread();
project.Save();
I tried the same approach however I could not obtain IVsBrowseObjectContext from Project reference.
What am I doing wrong? Why the same code works for nuget but does not work for my extension?

If you want to obtain a reference to the Package object within VSPackage MSVS extension, you can do something like this:
class MyPackage :
Package
    private static
MyPackage _instance;
    public static
MyPackage Instance
        get
            if(_instance
!= null)
                _instance
= new MyPackage();
             return _instance;
class SomeOtherClass
     void Whatever()
           // use MyPackage.Instance

Similar Messages

  • How do a reference a container from one of its objects?

    If i have on object in a container, how do i reference the
    container from inside the object. For instance, if i have
    a textbox and i want it to change color depending on
    a value in the container, how do i get to the container.
    thanks for any help
    owen brandon

    If you are asking about AWT or Swing, the Component class has a getParent() method that returns a Container.

  • How do I reference a MovieClip from a class

    Hi. Trying to learn AS3 and having a hard time ; (
    I'm working on a game. I have a Ship class that uses addChild
    to add a linked Bullet MovieClip to the stage. The Bullet MC is
    linked to the class below. I've got it working so it moves up the
    screen, but now I need to build a hitTest, however I cant get
    access to a movie clip I've placed on the stage, "enemyDisplay_mc".
    How do I reference this MC? In AS2 I would just do a _root.
    Thanks!
    package {
    import flash.display.*;
    import flash.events.Event;
    public class Weapons extends MovieClip {
    private var _thisWeaponMC:MovieClip;
    private var _enemyHit:DisplayObject;
    private var _speed:Number;
    public function Weapons () {
    this.addEventListener (Event.ADDED,Initialize);
    private function Initialize (event:Event):void {
    //trace ("Weapons");
    _thisWeaponMC =
    MovieClip(this.parent.getChildByName(this.name));
    trace ("_thisWeaponMC: " + _thisWeaponMC);
    _thisParent = event.currentTarget.parent;
    trace ("_thisParent: " + _thisParent);
    _enemyHit = this.parent.getChildByName("enemyDisplay_mc");
    trace ("_enemyHit: " + _enemyHit);
    _speed=20;
    this.addEventListener (Event.ENTER_FRAME,moveShip);
    private function moveShip (event:Event):void {
    this.y-= _speed;
    }

    This code is called from my Ship class.
    The Ship class is the Base class of the ship movie clip.
    VulcanShot is the linkage class name of the bullet movie,
    it's base class is Weapons.
    Thanks!

  • How to obtain Sync Recovery Key from Android Firefox?

    Desktop sync is broken and instructs to obtain "Your Recovery Key" from a working device. Only working device is Android Firefox. What is the magic incantation to get Firefox (v21 beta) on Android to reveal the needed sync Recovery Key?

    You can use:
    *Android OS > Settings > Accounts > Firefox Sync > Pair a new Device
    This will give you a 12-character pairing key the you can enter in the desktop computer.
    You can look at this version of the about:synckey extension that I have modified to show the sync key in current Firefox versions (desktop and mobile).
    * http://www.freefilehosting.net/aboutsynckey-11-fnfx
    * [[/questions/942893]]

  • How to obtain most popular cities from my users table

    Hi.
    I've got a 'users' table:
    USER_ID --- CITY_ID
    1 ---- 32
    2 ---- 20
    3----- 32
    4 ---- 32
    5 ----- 17
    I would like to obtain the most popular cities from this table, and the number of occurrences. Is this possible to make it easy with an SQL statement?
    Thx

    Here is an example using the emp demo table -
    SQL> select deptno, count(*)
      2  from emp
      3  group by deptno
      4  order by count(*) desc;
        DEPTNO   COUNT(*)
            30          6
            20          5
            10          3You can find full details of aggregate functions like count, and group by and order by in the SQL Reference manual.

  • How would you reference respective video from diff class?

    Hi. I wanted to get a couple of points of view (if you're willing to look ) on how others would do this because Im not sure where to even start.
    I have a buttons class that puts 9 pictures on the stage and each one represents a different movie and leads to that movie when clicked (or will lead there once I figure out how to reference it to the specific movie).
    I have 9 movies referenced through XML. And I am using flvPlayer. Currenly I can only have one movie loading. I am not sure how to get each one to play upon click of the respective btn.
    Here is some of the code I think is pertinent if figuring how to go about this:
    ProjectOneButtons class
    //I have each picture loaded through an array and each button is waiting for the right code through a Switch statement:
    public function onButtonClick(e:MouseEvent):void {
         var releventImageAray:Array = this["rowOfImages" + MovieClip(e.currentTarget).row];
         var imageWanted:String = relaventImageArray[MovieClip(e.currentTarget).column];
         switch (imageWanted) {
              case "Video1" :
                   //Have not figured out the specific video code in class below
                   //This switch statement continues for the rest of the buttons.
                   //this code works but it just loads one movie and so I don't think this is what I need.
                   projectOneVideos = new projectOneVideos();
                   addChild(projectOneVideos);
                   projectOneVideos.x = 0;
                   projectOneVideos.y = 0;
    Here is the ProjectOneVideos class where the videos are loaded and played:
    package asFiles.projectOne{
         //import statments taken out for post
         public class ProjectOneVideos extends Sprite {
              public var videoX:Number;
              public var videoY:Number;
              public var projectOneVideos:XMLList;
              public var projectOneTotal:Number;
              public var projectOneXML:XML;
              public var xmlLoader:URLLoader;
              public var player:FLVPlayback;
              public var playBtn:VideoPlayBtn;
              public var pauseBtn:VideoPauseBtn;
              public var videoContainer:MovieClip = new MovieClip;
              public function ProjectOneVideos() {
                   xmlLoader = new URLLoader();
                   xmlLoader.load(new URLRequest("projectOneVideos.xml"));
                   xmlLoader.addEventListener(Event.COMPLETE, processXML);
              public function processXML(e:Event):void {
                   projectOneXML = new XML(e.target.data);
                   projectOneVideos = projectOneXML.VIDEO;
                   projectOneTotal = projectOneXML.length();
                   makePlayer();
                   addButtons();
              public function makePlayer():void {
                   player = new FLVPlayback();
                   player.skinBackgroundColor = 0x47ABCB;
                   player.skinBackgroundAlpha = .85;
                   player.x = 40.3;
                   player.y = 220;
                   player.width = 1200;
                   player.height = 594.2;
                   videoContainer.addChild(player);
                   player.addEventListener("complete", backToVideoMenu);
              public function addButtons():void {
                   trace("addButtons initiated");
                   playBtn = new VideoPlayBtn();
                   videoContainer.addChild(playBtn);
                   playBtn.x = 625.6;
                   playBtn.y = 930;
                   pauseBtn = new VideoPauseBtn();
                   videoContainer.addChild(pauseBtn);
                   pauseBtn.x = 625.6;
                   pauseBtn.y = 930;
                   pauseBtn.visible = false;
                   addChild(videoContainer);
                   videoContainer.x = 0;
                   videoContainer.y = 0;
                   playBtn.addEventListener(MouseEvent.CLICK, playVideo);
                   pauseBtn.addEventListener(MouseEvent.CLICK, playVideo);
              public function playVideo(event:MouseEvent):void {
              // this is where I have the video referenced to play.
                   trace("play/pause button clicked");
                   if (player.playing || player.paused) {
                        if (player.paused) {
                             player.play();
                        } else {
                             player.pause();
                        playBtn.visible = player.paused;
                        pauseBtn.visible = ! player.paused;
                   } else if (player.stopped) {
                        player.play();
                        playBtn.visible = false;
                        pauseBtn.visible = true;
                   } else {
                                    //this will obviously not work because then its just this one movie referenced
                        player.play("videos/projectOneVideos/videoOne.f4v", 0, false);
                        pauseBtn.visible = true;
                        playBtn.visible = false;
    The reason I included a bunch of code is to show that there is a play/pause button that is supposed to play the movie. But the thing is I only have the one movie referenced and I am not sure how to have it variable as to which movie is played and make it depend on the button that is clicked from the button class above.
    thanks for any input you can give!!! 
    Note: All of this code works as it is and I am getting no errors.

    Ok, how about this:
    After reviewing my code again, this is what I find.
    I process the xml and then never use it when playing the video. To play the video I had just put the path straight to the video and not even used the xml. In the xml.
    So I guess my question is how to I refer to the xml to load the video and then when dealing with the buttons lead to the right video from the xml.
    kglad: Now I think I see why you were saying define a method of the ProjectOneVideos class that accepts a path/name string to the load target.
    I think the code I need to change is:
         if (player.playing || player.paused) {
                        if (player.paused) {
                             player.play();
                        } else {
                             player.pause();
                        playBtn.visible = player.paused;
                        pauseBtn.visible = ! player.paused;
                   } else if (player.stopped) {
                        player.play();
                        playBtn.visible = false;
                        pauseBtn.visible = true;
                   } else {
               //this is the part that needs to be changed to recognize from the xml
                        player.play("videos/projectOneVideos/videoOne.f4v", 0, false);
                        pauseBtn.visible = true;
                        playBtn.visible = false;
    But then I have to be able to pull the right video when I hit the button.
    So, what tools should I be using?

  • How do i reference a container from inside an object.

    if an object is in a container, how does the object
    fetch a value stored in the container. do you
    have to pass a reference to the container when you
    create the object. In Visual Foxpro it is easy, you
    this go
    value = THIS.PARENT.GetValue().
    what is the best way to do this in java?
    thanks for any help
    owen brandon

    I'm not sure what you're getting after -- maybe you could explain your actual setup.
    Taking a SWAG:
    If you have a textfield within a panel, you just reference the textfield directly. The container is just for visual organization.
    If you have a textfield in a different frame, you need to make the textfield public (i.e. no access modifier) or you need to make the textfield private and provide accessor (and maybe a mutator) method for it (i.e. create your own getValue(Object component) method to grab the data.

  • How do you reference assembly resources from MP in PowershellGrid Widget script

    Instead of shipping my custom assemblies to a known location on the system center 2012 server in separate files, I'm trying to use assembly resources to do this.  The issue I am having is referencing these assemblies in the script for the PowershellGrid
    widget I am using.
    As suggested in technet answer -
    https://social.technet.microsoft.com/Forums/systemcenter/en-US/e752fb63-0d5f-43e3-a2be-7db54934e29a/how-to-use-attached-to-bundle-dll-resource-in-powershell-module?forum=operationsmanagerauthoring
    I am using this convention -
    $FileResource[Name=”MyResource”]/Path$
    To illustrate what I am using, I've put in an exception to try and return the assembly path -
    throw "Test that the Assembly Path is returned:" + "$FileResource[Name='PaulsMP!DSUtilsTest']/Path$"
    Part of the exception is the following where you can see the Path$ has not been translated -
      [Microsoft.SystemCenter.Visualization.Component.Library.DataProviders.PowershellProvider,
    Microsoft.SystemCenter.Visualization.Component.Library.DataProviders, Version=7.0.5000.0, Culture=neutral,
    PublicKeyToken=31bf3856ad364e35].Test that the Assembly Path is returned:[Name='PaulsMP!DSUtilsTest']/Path$ ---> 
    So the questions are - can these assembly resources be referenced in Powershell grid widget scripts and if so, what is the syntax?
    BTW, my MP resources fragment looks like this - 
    <Resources>
    <Assembly ID="DSUtilsTest" QualifiedName="DSUtilsTest1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" FileName="DSUtilities.dll" Accessibility="Public" HasNullStream="false"
    />
    </Resources>
    Many Thanks,
    Paul  

    Paul,
    I was unable to find info specific to the issue you are hitting, however I've found the following links that I believe can help you:
    http://www.systemcentercentral.com/scom-2012-create-an-mpb-to-deploy-files-using-vsae/
    http://overcast.fehse.ca/2014/08/scom-management-pack-bundles-and-vsae
    hth,
    Jose

  • How to obtain a session object from session id

    Hi all,
    let say that I have a list of session ids, and I want by scheduald task to check whether the session is alive\active.
    I saw that the HttpSessionContext was deprecated. (see: http://javasolution.blogspot.com/2007/08/getting-session-object-using-session-id.html)
    Is there any other way to check if the session is alive?

    Do it the other way: let the session itself notify that it is not alive anymore.
    Implement a HttpSessionListener which adds the session to list/set/map on create and removes the session from it on destroy, register it in the web.xml and run it.

  • How do I reference a cell from within a condition in Numbers?

    I am trying to use the SUMIF function to sum values within an array IF corresponding values in the array are greater than a value in a corresponding cell. So:
    ___A____B____C
    5/23/12 1
    5/24/12 2 May 24, 2012
    5/25/12 3
    5/26/12 4
    Here is the formula I am trying to use:
    =SUMIF(A1:A4,">"C2,B1:B4)
    This gives me a syntax error. In Microsoft Excel I could get the result I want with the following formula:
    =SUMIF(A1:A4,">"&C2,B1:B4)
    You need that & to "build" a condition statement in Excel. But I don't even see the option to type in a & in a formula in Numbers.
    Is this possible in Numbers and if so, how?
    Thanks very much for any assistance.

    OK, I solved it.  The formula DOES work if you include the & character in Numbers, and that character is in fact sitting right in front of you in the upper left part of the text input area--you just have to toggle the "operators" section of the input area once to get it.  Sorry to bug everyone.

  • ADF JSF 10.13 how do you reference a binding from a command button?

    I have developed the following code as a model as I am trying to utilise ADF JSF without using a database.
    I have a collection called School. This has the appropriate operations that populate the school with a number of Child. A Child simply has a firstname and a surname.
    I have generated data controls for these collections and created two JSP pages and added a navigation link as follows:
    index.jsp --> goToSchool (navigation) --> school.jsp
    I have then added a command button to the index.jsp page. When the button is then pressed the school.jsp page is displayed. This works correctly.
    I would like to override the action of the button though so that before the navigation is executed I can get a handle on the school collection and populate it so that it will be displayed on the school.jsp page.
    I have previously done this in 10.12 when I had the following setup:
    index.jsp --> getSchool (dataAction) --> school.jsp
    by overriding the getSchool dataAction.
    I have looked through the 10.13 ADF user guides and tried various different things but have not managed to successfully acheive my goal of populating the school collection when the button is pressed prior to navigating to the school.jsp page.
    I would appreciate it if you could offer any advice, and if possible let me know the recommended best practices to acheive this.
    Thanks in advance for your help
    David

    Check out the ADF Tutorial (TopLink edition) chapter 5 has a section called:
    Adding a Drilldown Link
    I think this is what you are looking for.
    http://www.oracle.com/technology/obe/ADF_tutorial_1013/ADF_tutorial.pdf

  • I have read some forums but cannot obtain a still image from iMovie.  How do I do this in iMOvie 11 9.04.

    Hi
    Can anyone tell me how to obtain a still image from iMovie 11 version 9.04.  I have read some forums but cannot find the solution.  I have also read the Apple help pages but the instruction does not fit the options available.  I need to get a few stills from a movie to add the stills to the website.  PLease any help?

    Thank you Neil,I have a macbook pro with snow leopard v.10.6.8.included intell core 2 duo with a processor speed 2.5ghb with one processor and cores 2.
    can i download onto my laptop an update  by internet to my imovie 8.0.6 directly or as i have read, the system will not let me do that unless i have imovie 9.0.0 already which i do not have.
    Perhaps i misunderstand you. Do you mean purchase a software copy from an apple Store and the can i directly upgrade.

  • Valuations default profit center, how to obtain the original profit center?

    Hi Experts,
    Currently our valuations are being booked; they book the BS Account vs Unrealized Exchange Gain or Loss.
    The Profit Center for that BS Account is being determined automatically by the 3KEH table. Is there any way to derive the profit center from the Original Line Item?
    Example Entry
    PK     Account     Amount     Profit Ctr     
    40     10403494     549.21     OO6376DDD      BS Account - How to obtain the profit center from the original postin?
    50     37300104     549.21-     OO6376AAA  Exch Gain/Loss
    Thanks.

    Hi.
    '2. I know its going to be reversed the next month, our concern is that the amount that is going to the default profit center then will be allocated via cycle based on SKF so reflecting the data in profit centers that are not the ones that were originally affected.'-actually you can exclude adjustment account from sender while allocating,but it's better to substitute with right PC.
    '3. any logic on how substitution might work?' in fibf you can use process 1120
    'will it bring performance issues?'-no
    '1. How can this be worked via Doc Split for Unrealized? Do you have any example.'-it's not clear a question
    Edited by: alex ice on Apr 14, 2011 11:12 PM

  • How to Obtain a Distribution Provisioning Profile from Apple

    hi everybody!
    I'm searching in the apple.com site where I can register me to obtain a distribution provisioning profile, can anybody help me?
    thx!

    Hi Angelo, and welcome to the Dev Forum!
    A provisioning profile is one of the documents you can obtain at the Developer Program Portal once you're a member of the program. Normally you would first register as an iPhone Developer at the iPhone Dev Center to access the free developer tools and the extensive iPhone Reference Library.
    The home page of the iPhone Dev Center includes a link to information about the iPhone Developer Program. Once you decide on the type of membership you require (e.g.: Standard Program $99; Enterprise Program $299), you can proceed to the online application form.
    Once you are accepted into the program (the waiting time may vary from less than one day to several weeks), you will obtain access to the Program Portal which provides detailed instructions on how to obtain, install and use the various documents including the provisioning profiles. Note that an iPhone developer does not normally obtain a Distribution Provisioning Profile until completing and thoroughly testing an iPhone app using one or more Device Provisioning Profiles. A Distribution Certificate and Profile is only used when building the version of your app which will be submitted for review and placed in the iTunes Store if accepted.
    Hope that helps!
    \- Ray

  • Power Query; How do I reference a Power Pivot table from a Power Query query

    Hi,
    It's pretty awesome how you can define Extract Transform and Load processes within Power Query without having to type in a single line of code. However how do I reference a Power Pivot table from a Power Query query to avoid me repeatedly accessing
    the same data source (CSV) file with a view to increasing performance?
    We are aware of the reference sub menu option with Power Query. However the new query created by the "reference" option still seems to refresh data from the data source (CSV) rather than just referencing the base query. Is this understanding
    correct? There does seem to be a lot of hard disk activity when re-running the new query which is based on a base query rather than a data source.  So we were hoping the new query would just need to reference the base query in memory rather than rescanning
    the hard disk. Is there any way to ensure that the reference query just rescans the base query in memory?
    Kind Regards,
    Kieran.
    Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/

    Hi Kieran,
    This sounds like something to be suggested for a future release. At the present time, Power Query will always re-run the entire Power Query query when refreshed. The Reference feature is analogous to a SQL view whereby the underlying query is always re-executed
    when it's queried, or in this case refreshed. Even something like using the Power Query cache to minimise the amount of data re-read from the disk would be helpful for performance but the cache is only used for the preview data and stored locally.
    It would be a good idea to suggest this feature to the Power BI team via the feedback smiley face.
    Regards,
    Michael Amadi
    Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful :)
    Website: http://www.nimblelearn.com, Twitter:
    @nimblelearn
    Hi Michael, 
    Glad to hear from you about this.  And thanks to Kieran for bringing a very good valid point to debate. Will be glad to see this in future release. 
    - please mark correct answers

Maybe you are looking for

  • Stopping a Thread (no control on run method)

    Hi, How can we stop a Thread like in the following scenario. If we are in the aMethod() and the stopped variable is set to true by some other thread now how can we return from this run method and stop executing the aMethod(). Any tips are helpful. pu

  • Cursor Mouse Over on Frame (Container) Reveals Frame Edges

    I just installed InDesign CS5 and everything is fine, but there is a set preference that I want to remove that causes the edges of the Frame(s) (or Containers) to light up as I move my mouse cursor over them. I personally find this really annoying an

  • Streaming Album Covers

    Any ideas on how to get new/replaced album art to show up on the ATV? I use the itunes album art as my screen saver when streaming itunes thru ATV, and originally many of the covers were of poor (non-HD) quailty. I've now gone thru my entire itunes m

  • HP Connected Music after recovery?

    HP Pavilion Ultrabook 15-b005eo with Windows 8 64bit. Another question for today. Last week I purchased this laptop, yesterday I did a factory reset because HP 3D DriveGuard had stopped working by telling me that hard drives are not supported. I trie

  • HT4539 where is the store menu

    WHERE IS THE STORE MENU?