Converting from console to windows app in visual studio - visual-studio

When changing the project from console to windows app, I still am not able to use the namespace System.Windows.Forms. Do I really need to create a whole new project? If there is a better way, please give a detailed description of how to do this in visual studio step by step, thanks :)

The Console Application project template that you started with does not have the necessary assembly references. Project + Add Reference and select System.Drawing and System.Windows.Forms.
Also be sure to make the necessary changes in the Program class. Main() must have the [STAThread] attribute and you need to add the boilerplate code to enable visual styles and start the message loop. Take a look at a sample Windows Forms project to get that right.

You can use Windows.Forms independent of the the type of project. All you need is a reference to it. In your solution explorer you will find a folder "References" just under your project folder.
Right-click and choose "Add Reference". Scroll through the list and add System.Windows.Forms (and probably System.Drawing).

Related

Can I make a windows form application in Microsoft Visual Studio Express 2013 Windows 8?

Seems likely that I am not able to create a windows form application using the Microsoft Visual Studio Express 2013 under Windows 8. The default templaters are only for creating apps rather than traditional normal windowed applications.
Is there any way I could find the template or find a solution?
Thanks.
You cannot.
Download Microsoft Visual Studio 2013 Express for Windows Desktop instead.
Link for online installer
Link for ISO file
Visual Studio download page
Actually yes, you can do that manually, by adding the references to the project (System.Windows.Forms) and changing the output type in the properties of the project, and adding classes - you have to manually do the whole thing..
To Expand RobDev's answer, you can actually do this. I will show you an example of how to do this in Visual Studio Express 2015 for Web, probably same applies for 2013 version.
Steps.:
Create an empty solution
Create a .dll library project
Change output in project properties to Windows Application. To do so, right click on the new added project and pick "Properties". There, you can change "Output Type" dropdown in Application tab.
Add a reference to System.Windows.Forms to your project (by right-clicking => Add Reference to your Reference option under your project)
Set the project to Startup Project, by right-clicking the project and choosing "Set up as Startup Project"
add a main method to the generated class (you can rename it to Main). It will need this code to start.
using System.Windows.Forms;
namespace ClassLibrary1
{
public class Class1
{
public static void Main()
{
Application.Run(new Form());
}
}
}
and voila! That will create a new fresh Form. You could use a starting point whatever form you want. To do so, add a new .cs class and make it inherit from Form class.
The toolbox to customize forms is available at View => Toolbox menu.

Debuging MEF without main app visual studio project

I am creatinig Managed Extensibility Framework extensions for some program. That program uses dll files witch i create. I dont have visual studio project of that program, but i have that program. I can run these extensions using that program, but cant debug them properly.
Is it possible to use visual studio debugger to debug my code?
I found solution to this, thanks!
I found solution to this by my self, but thanks for sugestions.
I can use that app for which i am creating this extension, class libary project.
I press properties on project, then select debug tab and set "start external programm" an set it o that main app. then i press f5 and that app starts and when it uses my extension i can debug it using visual studio debugger. And i forgot to tell that i am creating this in C#.
http://msdn.microsoft.com/en-us/library/68c8335t.aspx
I believe what you are looking for can be found here:
http://msdn.microsoft.com/en-us/library/0bxe8ytt.aspx
According to this article, you could use the "Add Existing Project" dialog in you solution (for your DLL) to add the executable that you do not have the solution for. Because you are using MEF, it might get a bit tricky and you might want to create a new solution for debugging instead. However, this seems to be the general way to handle your situation. Since you have the source code for your DLL, I believe it should allow you to step through your code fully at the very least.
Note: You will need to make sure you have Visual C++ installed in your development environment.
If you are trying to debug the assembly code, then you can use the technique discussed by #BiggsTRC, if you are simply trying to identify why parts aren't being loaded, you could consider looking at the Composition Analysis Tool (mefx). This is a command-line tool for analysing a set of parts and finding out where failures may occur during composition.

How to include sharppcap library into Visual Studio?

Sorry for the noob question. I don't really know how to make sharppcap library working in my project. I'm using Visual Studio 2010.
Right click on your Project in Visual Studio-->Select Add reference --> Browse --> find the Sharppcap library and click done.
You should now be able to use the Sharpcap library in your project.
In your application find Reference option, right click on it and select Add Reference. Choose your sharppacp.dll and add it.
At last write using sharppacp ; in your application.

How to perform "shell" icon embedding in Visual Studio 2010?

As far as I can tell, there have been (at least?) three types of icon embedding. There's the original style used by shell32.dll and friends, .NET's embedding, and the new type that WPF uses. I'm looking for how to perform the first one, as I want to have a few other icons available as resources for a jumplist, which can only accept that style. However, I can't figure out how to embed in this style, only the other two.
How do I do this? All the results I find on google, etc are for adding icons to ResX files or similar.
I never heard the term "icon embedding" before. If you are talking about the icon that's visible for a EXE or DLL in Explorer or a desktop shortcut: that's done the same way for any Windows program. Both WF and WPF give the assembly an unmanaged resource with the selected icon using the /win32res compile option. You can see it in Visual Studio with File + Open + File, select the EXE or DLL.
To create a .res file, first create a .rc file. You can create one with the C++ IDE. Right-click the solution, Add New Project, Visual C++, Win32, Win32 Console Application. Right-click the Resource Files folder, Add + Resource, select Icon, Import. select your file. Repeat as needed. After you build, you'll get a .res file in the project's Debug build directory.
Back to your C# project, Project + Properties, Application tab. Select the Resource File option and navigate to the .res file.
I'd highly recommend taking a look at this solution posted here (http://einaregilsson.com/add-multiple-icons-to-a-dotnet-application/). It integrates right into a ms build post build event and doesn't require an unmanaged project (to create an assembly from a .rc/.res file).
This removes a dependency on managing a second solution / assembly anytime you want update an icon and saves you from IL Merging the compiled c++ assembly.
I'd also recommend taking a look at WIX for your deployment. I've written a guide that accompanies this answer located here.

How can I reference a dll in the GAC from Visual Studio?

This assembly is in the GAC: Microsoft.SqlServer.Management.RegisteredServers.dll
How can I add a reference to this assembly in Visual Studio?
I can view the file in c:\windows\assembly\
As the others said, most of the time you won't want to do that because it doesn't copy the assembly to your project and it won't deploy with your project. However, if you're like me, and trying to add a reference that all target machines have in their GAC but it's not a .NET Framework assembly:
Open the windows Run dialog (Windows Key + r)
Type C:\Windows\assembly\gac_msil. This is some sort of weird hack that lets you browse your GAC. You can only get to it through the run dialog. Hopefully my spreading this info doesn't eventually cause Microsoft to patch it and block it. (Too paranoid? :P)
Find your assembly and copy its path from the address bar.
Open the Add Reference dialog in Visual Studio and choose the Browse tab.
Paste in the path to your GAC assembly.
I don't know if there's an easier way, but I haven't found it. I also frequently use step 1-3 to place .pdb files with their GAC assemblies to make sure they're not lost when I later need to use Remote Debugger.
Registering assmblies into the GAC does not then place a reference to the assembly in the add references dialog. You still need to reference the assembly by path for your project, the main difference being you do not need to use the copy local option, your app will find it at runtime.
In this particular case, you just need to reference your assembly by path (browse) or if you really want to have it in the add reference dialog there is a registry setting where you can add additional paths.
Note, if you ship your app to someone who does not have this assembly installed you will need to ship it, and in this case you really need to use the SharedManagementObjects.msi redistributable.
I've created a tool which is completely free, that will help you to achieve your goal. Muse VSReferences will allow you to add a Global Assembly Cache reference to the project from Add GAC Reference menu item.
Hope this helps Muse VSExtensions
In VS2010, from the Add Rerences window you can click 'Browse' and navigate to C:\Windows\Assembly and add references to the assemblies that you want. Please note that the files may be grouped under different folders like GAC, GAC_32, GAC_64, GAC_MSIL etc.
In VS, right click your project, select "Add Reference...", and you will see all the namespaces that exist in your GAC. Choose Microsoft.SqlServer.Management.RegisteredServers and click OK, and you should be good to go
EDIT:
That is the way you want to do this most of the time. However, after a bit of poking around I found this issue on MS Connect. MS says it is a known deployment issue, and they don't have a work around. The guy says if he copies the dll from the GAC folder and drops it in his bin, it works.
The only way that worked for me, is by copying the dll into your desktop or something, add reference to it, then delete the dll from your desktop.
Visual Studio will refresh itself, and will finally reference the dll from the GAC on itself.
Assuming you alredy tried to "Add Reference..." as explained above and did not succeed, you can have a look here. They say you have to meet some prerequisites:
- .NET 3.5 SP1
- Windows Installer 4.5
EDIT: According to this post it is a known issue.
And this could be the solution you're looking for :)
May be it's too late to answer, but i found a very simple way to do this(without a hack).
Put your dll in GAC (for 3.5 Drag Drop inside "C:\Windows\assembly\")
GoTo Projects --> Properties
Click Reference Path (for 3.5 it's "C:\Windows\assembly\")
and Build
Hope it helps
The relevant files and references can be found here:
http://msdn.microsoft.com/en-us/library/cc283981.aspx
Note the links off it about implementation/etc.
I found this extension for VS 2013 Vitevic GAC Reference.

Resources