opening c# files with visual studio outside of project gives no suggestions - c#

Im currently writing some very small c# exercises, for a algorithm course.
visual studio is my favourite IDE, and usually, when i create or clone a visual studio project, I get the full functionality of viusal studio including spellchecking and suggestions for fields and methods on objects and so on.
But right now I am just trying to open a single .csc file and write some code in it. The problem is that when i do that, i get no suggestions. So if I create a list I would usually be able to view all the methods and fields inside the list class simply be referencing an object. Syntaxm checking works fine.
How do I turn on intellisense suggestions in a file that is not in a project?
Thank you

The simplest way is simply to add that file to a project.
Open VisualStudio.
Create a new project (you can probably use Console project or Class library, depending on what you're doing).
Add your file in that project.
Make sure your file as the Build Action C# Compiler.
And that should work.

Related

Merge two versions of C# projects

I am working on documenting a winForms project that isn't completely done being written, meaning there is another programmer who write the code right now. So I've already wrote some importent comments in a copy of the project.
In addition I use sandcastle to bulid the help file.
My question: what is the best way (if there is one) to copy the comments from the old copy of the project to the new version of it?
Maybe sandcastle can do something like import a documentation to a project?
I know it wasn't so smart to do so, still I have to check if there is a way to save the documentation work.
Visual Studio has a built in file difference function you can use to see where the two files are different. It should be then a matter of copy and paste of the changes you have made over to the "gold" copy of the file your other programmer has changed.
This link shows how to Compare two files in Visual Studio 2012
"You can invoke devenv.exe /diff list1.txt list2.txt from the command prompt or, if a Visual Studio instance is already running, you can type Tools.DiffFiles in the Command window"

Changing Project Metadata in Visual Studio 2013 C#

I've got a Visual Studio 2013 package written in C# where I need to make some changes in the items and their attributes in a C++ project file while Visual Studio 2013 is running and has the project loaded. Actually, it could also be OK to save the project file at the point when the whole solution is being saved.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="Test">
<MyItemToChange Include = "TestItem">
<MyMetadata1ToChange>Value1</MyMetadata1ToChange>
<MyMetadata2ToChange>Value2</MyMetadata2ToChange>
</MyItemToChange>
</ItemGroup>
<!-- The rest of the file -->
</Project>
In previous Visual Studio versions I used the Microsoft.Build.Evaluation.Project class to change the items and the metadata of the project. When you have the reference to the project, you can either accessed the XML structure of the project directly through Project.Xml property or get a hold on different Microsoft.Build.Evaluation.ProjectItem and use the interfaces found there.
However, since Microsoft has changed the structure of Visual Studio in their 2013 release, though the Microsoft.Build.Evaluation.Project is not deprecated, you can't access the C++ projects any more through Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.LoadedProjects as the collection is empty. However it still works if you want to access C# projects. (As a matter of fact, browsing deep into the objects while debugging you can find that they still use the same Microsoft.Build.Evaluation namespace for inner representation.)
Since I can't access the Microsoft.Build.Evaluation.Project any more, I need an alternative to
access the project otherwise than using the
Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.LoadedProjects
write project items and metadata while Visual Studio 2013 is running.
Unless I've missed something, the following are not good for my purposes:
Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage.SetItemAttribute sets only attributes to items that are displayed in the Solution Explorer. "MyItemToChange" is not displayed in the Solution Explorer
Opening the file and manually editing and saving it. Unless you know how to suppress Visual Studio's warning about a changed project and how to auto reload it, it is not a way to go.
Note: You can close the solution, open the project file manually, edit then save it and reopen the solution. It would work fine, the data is there, unless the files are under source control. Now it opens up a whole lot of new issues (why EnvDTE.DTE.SourceControl.CheckOutItem() doesn't work, etc.) So I still think I would be better off if Visual Studio would handle writing data to the project file.
Reflection. Yes, as I mentioned before, I could dig into internal classes to get a hold on the "original" Microsoft.Build.Evaluation.Project, and Microsoft.Build.Evaluation.ProjectItem, but first of all, it is quite unsafe for future uses and as far as I remember, you cannot be sure that if you modify these now internal classes, the project will know that it is dirty and has to be saved.
I'm glad to have any suggestions as I'm really running out of options.
Thanks.
Well, I have worked out a workaround, not a real solution for the problem.
What I do right now is the following:
Ask the user whether they're OK with closing the whole solution and saving everything. If not, I cancel the whole procedure: EnvDTE.DTE.ItemOperations.PromptToSave
Try to ask Visual Studio 2013 to check out the project file for me in source control using EnvDTE.DTE.SourceControl.CheckOutItem() method. If it throws an exception (NotImplementedException), I use a bodge to check out the project file. That is, I write a custom property into the project file using Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage.SetProperty() method.
Close the whole solution. EnvDTE.DTE.Solution.Close()
Open the project file using the System.Xml.XmlDocument class. Edit. Save. Oh, and remove my silly property written in the 2. point (the one used to force Visual Studio 2013 to check out the file in source control.)
Reopen the solution. EnvDTE.DTE.Solution.Open() At this point the user might be asked again to confirm some source control options.
Why is it just a workaround not a proper solution?
It's ugly. :)
Methods are abused for things they are not meant to be used (writing a random property into a project just to force source control checkout)
It wouldn't work if closing the solution / project is not an option. E.g.: if you need to save something during build or while they are editing the solution / project / source files; or if you have to do it often not just once during the lifetime of a project.
I'm still looking for the proper solution for the problem. But until someone could tell me how it is done, I have to live with this current implementation.

Add Visual Studio solution to existing solution in Visual Studio

I wrote an application in Visual Studio C# 2010, that I would like to import into another existing Visual Studio C# 2010 Application. How would I go about doing this?
For instance, I'd like to import the project into another, and basically copy/paste the interface from the application into a tabpage on a tab control I have.
Any assistance or advice on how to do this is greatly appreciated!
You should be able to copy the physical files using windows from the existing solution location to the new solution location.
Then once the copy is complete open Visual studio and tell it you want to add an existing project. Navigate to the folder where the files are on the filesystem and open the project file.
Once you save the solution it should from that point forward have the new projects in the new solution.
There are several ways to achieve this - Copy & Paste being one of them (but the least beautiful of course). A more promising one is the following:
Wrap the user interface you want to share in a User Control in the existing project. Also include the code behind logic in this user control. Include the user control in the project and make sure that everything works before continuing.
Add the existing project to the new solution. It is advised that you create a hierarchical structure in the file system for the solution so that all projects in the solution are located under a directory.
Reference the project from the project that wants to access the user interface. As the projects are in the same solution, you can add a project reference. This asserts that the projects are built together.
Place the user control on the tab page.
As an alternative, you can also pass on adding the project to the solution but only create a user control and add a binary reference from the other project.

Where can I find the implementation for IVCWizCtlUI

Background:
I have an visual studio C++ custom project template to create a custom solution. When we say new project and select this custom template, it would ask for an xml file and create a visual c++ solution, substituting values from the xml file to the template files.
What am trying to do now?
I wanted to automate this process, (no user intervention to open visual studio and select the custom template). Infact to use the component in C#. This component has a dependency with visual studio wizard as shown in sample javascript
Difficulties faced?
The xml parser is a com component, which takes visual studio wizard as a parameter. Only if i set this properly, i can proceed further. The wizard is basically implements the below interface.
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vswizard.ivcwizctlui_members(v=VS.90).aspx
Not sure how to access this wizard in C#.
Current Javascript code:
var aConverter = new ActiveXObject("NAMESPACE.MYParser");
//Problem: Not sure how to set this value, when "NAMESPACE.MYParser" used in C#
aConverter.Wizard = window.external;
aConverter.Filename = xmlfile;
//This method if called from C# without setting "aConverter.Wizard" throws exception
aConverter.ParseMyXML();
var value = aConverter.Someproperty;
Prior research:
I tried to use dte.LaunchWizard, but still i get an UI popped up, which i need to avoid. LaunchWizard not a good way for me, as i wanted direct control in C# for "NAMESPACE.MYParser"
It may be not exactly the same direction as you want to go, but have you considered using CMake(open source) for that?
CMake is a tool for automatically setting up code-projects/toolsets on different plattforms and IDEs. CMake can also generate VisualStudio solutions, so all you would have to do is set up your CMake config files, and just generate the solution. You can also incorporate parameters, so that the user is able to costumize the project to be generated even further.
It is a great tool, runs on most platforms and there is also an easy to use GUI available. Check it out: http://www.cmake.org/

Any way to make Intellisense work, when opening a cs file that's not part of the project?

What we ideally need is, to know how Microsoft handles XAML generated code (Those *.g.cs files). If you goto a XAML code behind, intellisense will work even if the *.g.cs file is not part of the project!!
Context:
In a custom VS package, we need to have some logic to open a CS file (with out making it a part of the project) in the VS IDE, to allow the user to edit it.
We are hooking up the document to the Running document table and receiving the events like Saving, Close and all, using IVSRunningDocumentTable. Works good.
Now the problem is, when the document is opened, Intellisense can't work, for the simple reason that the opened document is not part of the project (sadly, we can't do that, we can't make it code behind).
Intellisense is driven by a memory cache of identifiers and types. These types are cached based on the project you are in and the references that project has. If the code file you are editing is not part of a project, Visual Studio would have to load every possible assembly and create intellisense data for each type in the entire .NET framework because it would have no way of knowing whether or not your code file required it.
I guess Visual Studio could load intellisense based on the content of the file but that is not the way it currently works.
Visual Assist X by Whole Tomato is an addin to VS I've been using for many years. It will give you Intellisense and more when you open it.

Categories