Adding UserControl from another project in xaml [duplicate] - c#

Iv'e downloaded a C# interval tree collection class class from here http://intervaltree.codeplex.com/SourceControl/list/changesets -> Right hand side -> Download.
However I can't open the whole project on my Microsoft Visual C# 2010 Express (that also runs C# XNA) because
Solution folders are not supported in this version of the application
Also I just want the class to use separately in my own seprate project.
I tried to copy the three important seeming files Interval.cs, IntervalNode.cs and IntervalTree.cs into my project but this generated the compile error
There are no importers which handle this file type
I've also tried to copy and paste the contents of the three files into my project, encapsulating them into there own namespace as well as there was a lot of code. I had to rearange some of the usings a little but have run into the problem that possibly it wants PowerCollections .dll and .pcb files as using Wintellect.PowerCollections; causes
The type or namespace name 'Wintellect' could not be found (are you missing a using directive or an assembly reference?)
I'm not sure how to continue or if I'm doing the right thing at all in how to get this class to work.

Add the library to your solution
Copy the IntervalTreeLib directory into your solution directory. Then, right-click your solution, and add existing project. Point it at IntervalTreeLib.csproj in IntervalTreeLib, and click Open. That should add the IntervalTreeLib project to your solution.
Add a reference to the library in your project
Then, in your project, add a reference to the IntervalTreeLib proejct:
- Right click the References folder, and Add Reference. Click the Projects tab, and select IntervalTreeLib.
Use the classes in your code
To use classes from the library in your source then, you need to either add:
using IntervalTreeLib;
void Foo() {
IntervalTree<int, int> tree = new ...
}
Or, refer to them by their full name:
IntervalTreeLib.IntervalTree<int, int> tree = new ...

Open the IntervalTreeLib.csproj file if you want to be able to open the project in it's entirety (or in your current solution add an existing project (you can right-click on the solution) and select the IntervalTreeLib.csproj). If you are trying to grab just the code file in your project, ensure you also grab the PowerCollections.dll file (I see it is in the same folder as the code files) or your code will not compile (as you have discovered). You'll need to add a reference to it and include the needed using statement at the top of the code files making use of this library (or use fully qualified name with the namespace).
using IntervalTreeLib;
or
var myObj = new IntervalTreeLib.[WhateverClass](...);
Also, make sure you read the license.txt file. You may need to include it if you are using the code. Give credit where it is due.
UPDATE:
If the test project is causing you problems, just open the library project. Ideally you could just open that and compile it, adding the output DLL files that are generated directly into your solution. This is ideal unless you are planning on changing the library source code itself.

Add the library to the references of the project you want to use it.

Since discussing that you are able to build Intervallib.dll, we will discuss about how you should the dll in your project.
Now in your proj, right click on the references part and add the dll intervallib.dll to your references. In your game.cs file, have the reference to the namespace as -- using IntervalTreeLib;
then you should actually copy the dll powercollections.dll to the bin directory of proj directory also.
you should copy this dll because there is an indirect link to the dll as it is used in IntervalTreeLib.dll
following these steps, I was able to execute this project.

Related

Where to define files required by many projects in visual studio?

Let's say I have 5 or 6 projects in my solution. There is a file called fileCopyHelper.cs that basically copies files from one folder to another. I need this file for a lot of projects in the solution and I don't want to keep redefining it in every project? How do I do it?
I tried adding a .cs file to the solution and Visual studio grouped it into Solution items folder. However I'm unable to access the classes defined in this file in my projects because Solution items is just a folder, not a project, so I can't add a namespace reference from other projects.
Add a new project to your solution, and select the class library type. This gives you a single place to add code that will be shared.
Reference the new project in whatever other projects in your solution need access to the code.
Your setup might look something like this, where the fileCopyHelper class is party of ClassLibrary1, which is then referenced and used in the main ConsoleApp1 application:

Refactor such as winForm.exe calls a .DLL

I have a windows application (winForms). I would like to refactor it such that all functionalities are built to .DLL file so that when winForm is run, it will just call .DLL. In addition, I would be creating another .exe which is Console App so when a user wants to just "schedule task" it, he will create a config file that will run the console app, which when run will also call .DLL
I don't have much knowledge about refactoring and compiling projects to .DLL (I hope I am making sense)
I just want to know if I am correct on how I quite understand it for now:
Should I transfer all my functionalities from winForms to a class that will be compiled to .DLL? Or if I am wrong, what should I put in a .DLL class?
You should create a new project in your solution. Create a class library project in your solution in Visual Studio (or tool of choice, you did not specify what you are using so I assume VS).
To add a new project, right click your solution and select Add submenu, then New project.
From the categories menu on the left, select Visual C#, then Windows, and Class Library.
Then you should add a reference to this new class library project from your current WinForms project.
Right click References in your current WinForms project and select Add reference.
Then select Solution category on the left (VS2012), or Projects tab (VS2010) and Select your newly created class library project from there.
Then you can start moving classes from your current WinForms project to this new class library project. Class library project will be compiled as a dll and you will have access to all classes in this dll from your WinForms project.
Nothing dramatic is needed. Just Project + Properties, Application tab, change the Output type setting from Windows Application to Class Library. Done. You may have to declare a class public if you didn't already do that. You could remove your Program.cs source file since it won't be used anymore but that is entirely optional. A good reason to not remove it is keeping your project testable.
Fwiw, changing the Output type setting is not actually necessary, .NET doesn't distinguish between a DLL and an EXE at all. The CLR loads assemblies by their display name, it doesn't include a filename extension. You can add a reference to your EXE assembly in another project and it will work just fine.
So doing nothing at all already works :)

Add compile parameter to csc command using Visual Studio IDE

The solution consists of two projects: main.csproj and helper.csproj.
What Id'like to do is using dll which helper project will be complied into, as an embedded resource for main.dll.
For that purposes it's seems resonable to add custom compile attribute for project main: /resource: <path to dll>.
The problem is I can't find how to add this compile parameter through the Project Property.
PS Maybe someone can suggest other solution to avoid making changes in compile process.
You should be able to add the helper assembly as a resource in the main.csproj. That will make MsBuild generate the correct parameters for csc.
(MsBuild is the build engine used by .NET in general up to and including 4.x and is also used by VisualStudio.)
What you can do to set this up is:
Right click the Main project in the Visual Studio solution explorer and select Add existing item. Add the assembly to be embedded as a linked item from the bin folder of the helper project. (click the little arrow on the Add button in the selection dialog to access the option to add as a link).
In the properties for the item in the Main project, set Action to Embedded resource.
Tricky bit would be to include the correct build so that you include the debug build or the release build depending on what configuration you are building.
If you need that, you can either:
edit main.csproj file to include the ${Configuration} variable in the path for the helper dll.
Add a pre-build step to the main.csproj file to copy in the assembly to a fixed place and include the file from there (the include as link bit is no longer needed then)
To make sure you always build the helper assembly when you build the main assembly I would recommend you add a project reference to the main project.

how to use same name class libraries on a solution

Need to add two same name .csproj class libraries in my solution.Have two project but unfortunately those project class libraries names are same,like: Hello.csproj.I try to add existing project on solution then show me error
http://blogs.msdn.com/b/ansonh/archive/2006/09/27/774692.aspx
from above url I learned how to use same namespace dll on same project ,but I need help how to use same classlibraries on a solution
if have any query please ask,thanks in advanced.
Note:ok people want to know the reason,i have two project on Autocat 2005 and 2010,now want to merge those project on one solution,2010 update base on 2005 so class libraries are same,but i need to use both of them.So problem arise and seeking help.
You can have projects with the same name as long as they are already created in different folders and they are in different solution folders. If the projects are already created, do this to add them to your solution:
Add your first project to the solution.
In Solution Explorer window, right click your solution and select Add->New Solution Folder
Give a name to the newly created folder.
Right click the folder and select Add->Existing Project
Navigate to your second project and double-click the .csproj file.
You're done.
If you really must do this, then ensure the second project has a different name, and then change the namespaces of the classes in the second project (normally the project name comprises the first part of the namespace - just change that part). The classes will still be identical internally, but because they have a different namespace they will be distinct entities. This will lead to very smelly code though when you start mixing them up in the ClientApp - to avoid confusion make sure you always refer to them by their full namespace (i.e. do not have a using xyz.myclassname; statement at the top of the class file that uses them).
Maybe you want to run two (almost identical) instances of the same service or something, but as mentioned it is hard to think of a genuine reason why you would need to do this. If you are looking to have two identical looking instances but different implementation then you will want to use interfaces instead.
Edit: Visual Studio will not allow you to have two identically named projects, and you are playing crazy games if you change a project name but don't change its project GUID (in the .proj file and the .sln file).
The simplest thing for you to do here is to create a new empty project in the solution explorer, right click on it and Open folder in Explorer, then copy the class files from the original project to the new one, then back in the solution explorer choose Show all files (little button at the top of the solution explorer), then select the newly added files under the new project, right click, Add to project. (These menu options are from memory, they should be roughly right).

Visual Studio 2010 dll create error

I am new to C# programming and I have a problem with dll creation.
I opened a class library project and write public static methods in my classes. Clicked debug and copied dll and pdb files (under bin/debug/..) to my WPF application project.
I didn't get any reference problems also editor shows my methods normally, also when I use them it gives me no error or warning...
However, when I run my program, I saw that my methods calling dll methods are not working. In addition, debug mode also jumps my methods so I cant trace the code.
Where am I doing wrong? Is there any other way to create dll or am I missing a trick in here?
Thank you..
Rather than copying the DLLs into your WPF app's bin directory, you should either add a project reference to your class library from your WPF app, or add a reference to the output directory of the class library. Otherwise the build is probably copying over your hand-copied files. Basically, you should treat anything in bin as "controlled by Visual Studio" IMO - don't copy anything there manually. It helps if you use project references rather than referring to specific files, too - that way each build gets an appropriate configuration for its dependencies.

Categories

Resources