Visual Studio Extensibility Package not looking at correct project - c#

I have created a new VS 2010 extensibility package. So far, all I want to do is have the user press a button and fill a listview with the entire contents of the solution. I have the following code:
EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.
GetActiveObject("VisualStudio.DTE.10.0");
foreach (Project project in dte.Solution.Projects)
{
foreach(ProjectItem pi in project.ProjectItems)
{
listView1.Items.Add(pi.Name.ToString());
}
}
This does seem to work, however, it populates the list with the contents of the solution with the package in it and not the experimental instance that is launched when this is run. Am I instantiating the reference wrongly?

GetActiveObject method returns first process instance of DTE, not
caller DTE. (in Visual Studio SDK 2010 project on Visual Studio 2010,
type F5 to execure experimental hive may fail)
Look at here and here for more details...

No - you need to use ProjectItem.SubProject to get to what you want... depending on the solution structure some recursion could be needed... for some sample code doing nicely all this see http://www.wwwlicious.com/2011/03/envdte-getting-all-projects.html

Related

Issue with Visual Studio 2022 Intellisense Complete Word function?

Create an ASP.NET Core project. I created it using the new Empty template using .NET 6 but it shouldn't matter. I then compiled the app.
In program.cs, locate the line where the builder object is instatiated. Add it if it is not found.
var builder = WebApplication.CreateBuilder(args);
After the above added line, type the incomplete following line of code and then, with your cursor at end of the unfinished line, click the shortcut control + space to execute the menu command Edit->Intellisense->Complete Word
builder.Services.AddS
I expected the intellisense to pop up and pre-select "AddScoped" in the list. But it just sat there.
Intellise generally works but not always. This is one example where it doesn't, at least for me.
Does it work for you? Should it work as I described? I'm thinking so...
I'm using the following version if VS:
Microsoft Visual Studio Professional 2022
Version 17.4.0
VisualStudio.17.Release/17.4.0+33103.184
I was having the same issue. Used Visual Studio Installer and executed a 'repair'. Everything works now!

How to Get callback after Visual Studio Solution gets Build through VS SDK?

I am using code written below..
EnvDTE.DTE dte = (EnvDTE.DTE)Marshal.GetActiveObject("VisualStudio.DTE.12.0");
dte.ExecuteCommand("File.SaveAll"); // Saving all files before building
dte.ExecuteCommand("Build.ReBuildSolution"); // Buidling solution
I want to execute subsequent code statements only after successfull build of solution .
Is there any callback defined which notifies successful/unsuccessful build ..
First, if you are using an extension (add-in or package), don't use that way of getting the DTE instance, because Marshal.GetActiveObject(...) returns a running instance of DTE, and if you have two instances of VS open, you could get the wrong instance. The correct way is:
For add-ins: the instance passed in the OnConnection method.
For packages: see HOWTO: Get an EnvDTE.DTE instance from a Visual Studio package.
Second, see the article: HOWTO: Performing some action before or after a build from a Visual Studio macro or add-in
The best approach is to use the IVsBuildableProjectCfg.AdviseBuildStatusCallback method to get IVsBuildStatusCallback.BuildEnd called and check the fSuccess parameter.

Add programmatically Visual Studio Solution and Projects

I am trying to generate a Visual Studio 2010 solution and add VS 2010 projects from custom templates!
My requirement:
1. Generate a VisualStudio Solution 2010, Save it to a folder, add VisualSTudio Project from my own templates (I have 3 different templates: ClassLibrary,WinForms ,WCFService)
My issue:
I implemented something that is working half a way!
Solution is created correctly but the content of the ".sln" file is very poor! No project reference is added >
In the root folder, it creates a Solution also for the C# Project, which I do not want. I want only the MainSolution file. (In my case "TestSolution.sln"). How can I stop creating a solutionfile for each project created?
Below the source code I use:
//for The solution:
//adding a project
Am I using the wrong interfaces?
Why the vs2010Solution.AddFromTemplate(..) returns null after the call, but no exception is thrown? Also the Project is created correctly in the folderstructure! But at runtime I can't check the list of projects "vs2010Solution.Projects" as it is null! (After correctly adding a project). I need the Project added because I need to add some references programmatically, which I try to do in the next line, but it doesn't work because vs2010Project is null).
So I am trying to wrap the VisualStudio 2010 automation model, to create a solution and add projects! But is not really working! Do I need to cast EnvDTE.Project to "VSLangProj.Project" at some point? I want to create a clean wrapper for VS2010, after that one for VS 2012!
Any help is much appreciated.
See the several articles of the section "Articles about automating project creation" on my web site:
http://www.visualstudioextensibility.com/articles/add-ins/
They explain why AddFromTemplate method returns null, how to create a solution, a project, a project inside a solution folder, a project item, etc.

Cannot run Roslyn Samples under VS2015 CTP 3

I downloaded Roslyn code and built it successfully within VS2014 CTP 3. I am trying to run the samples that came with the source as part of Samples.sln solution. I can build Samples.sln successfully.
I try running ImplementNotifyPropertyChangedCS sample - I made the project the startup project within the solution and pressed "Start Debugging" menu item. As a result I am getting another VS2014 instance. I open a new project within that instance, create a property and try to refactor the property. I am not getting the option to Implement Notify Property Changed refactoring.
I checked the dependencies of the new instance of the visual studio - it does not depend on ImplementNotifyPropertyChangedCS.dll file. I looked at the output window of the first devenv instance - it seems like that ImplementNotifyPropertyChangedCS.dll was loaded but later was unloaded.
Please help.

Microsoft Visual Studio 2012 cannot set breakpoint in c# file

I have Microsoft Visual Studio Professional 2012 installed, version 11.0.60610.01 Update 3.
When debugging a c# (.cs) file Visual Studio gives me the following message when I try to set a breakpoint:
"A breakpoint could not be inserted at this location".
I get this message even when trying to set it on a line within a method. But in a .vb file for a Visual Basic app, I can set a breakpoint.
I am wondering if anyone has any suggestions to resolve this or if I need to reinstall visual studio.
Thanks
Maybe I'm too late for this question but here it goes anyway,
BUILD > Clean Solution
BUILD > Build Solution
I have encountered a similar issue and I resolved it by exiting Visual Studio and deleting the .suo file from my solution folder.
This file is recreated when you open the project again and it is not harmful to delete it.
The .suo is used for storing the layout of your solutions, the breakpoints you've set, the tabs you had open, etcetera.
I am not sure why this worked but my logic was that Visual Studio thought I was trying to place a breakpoint in a location different to where I was actually placing it.
I was finally able to find a solution for this. I had to do a repair on my Visual Studio 2012 instance through the control panel -> Programs and Features, right clicking on Microsoft Visual Studio Professional 2012, and selecting change. In the Visual Studio window I then selected repair.
As part of the repair process, I also had to download web deploy located here: http://www.microsoft.com/en-us/download/details.aspx?id=4148 and point the visual studio repair process to the .msi file when it said it couldn't find the web deploy package and could not download it from the internet.
I also had to implement the fix indicated in the following stackoverflow question: Plain C# Editor in Visual Studio 2012 (No intellisense, no indentation, no code highlighting)
Now I am able to debug applications as expected.
Well, sheesh...for people as dumb as me, here's one more thing to consider:
You can put breakpoints on the curly braces at the start or close of a method, and you can put breakpoints on any line that is doing something (e.g. assigning a value or calling a method). However, you can't put a breakpoint on a line that is only declaring a variable or otherwise "doing nothing."
E.g. I had a method:
public IEnumerable<SomeObject> GetList()
{
int distance;
var otherVar = SomeValue;
}
I was trying to put the breakpoint on the first line with int distance;, which is something that works fine in other IDEs, but that doesn't work in VS. I had to go up to the brace or down to the next line with the assignment in order to get the breakpoint to set.
5 minutes of my life wasted, that I'll never get back, trying to debug a non-issue ;-p
VS 2017
I had this, I was missing an ; inside a for loop
If there is no instructions to execute on a line, VS refuses to set a breakpoint an offers no reason. EG
string str; //Cannot set breakpoint
string str = ""; //Can set breakpoint

Categories

Resources