I currently have a library which was created in a silverlight application for its use. But Now we are switching over to WPF. So i don't know how would i convert the library to a wpf library. Would i just have to copy all the file in a new project(wpf class library)
As you can see when i reference this silver light library in my wpf project. It gives me a warning.
As the message says, you can't use a project compiled to target Silverlight as a reference for a project targeting some other .NET framework family. You will need to compile a separate assembly compatible with the .NET framework family you're using (i.e. a desktop version). This will require the creation of a whole new project (I'm not aware of a practical way to have a single project target both Silverlight and desktop .NET).
Note that the new project can use the same source files as the original Silverlight one. After creating the project (which you should create as an "Empty Project"), you can add the source files from the Silverlight project, by using the "Add Existing..."/"As Link" option for adding items to the project. Adding the source code as links will cause the new project to reference the original .cs files in their current location rather than creating a new copy of them for the new project.
Note also that your Silverlight code may or may not be 100% compatible with the WPF API. You may have to introduce conditional compilation (i.e. use #if, and declare appropriate conditional compilation symbols, in the projects' settings "Build" tab) so that you can provide correct code for each platform in each .cs file.
Related topics (there a lot of duplicate questions involving adding existing items as links…though many of these involve multiple solutions, not just adding items to a new project):
Share c# class source code between several projects
How do I keep common code shared between projects in c#?
Adding Existing Files To Different Visual Studio 2010 Project
Is it possible to statically share code between projects in C#?
Updating classes used in multiple projects?
Make reference to C# code from multiple projects
Share .cs file among VS 2010 C# projects
How to include source files of one project in another project?
I have a file coded in VB that I need to reference and use in my C# program. I am having trouble getting my C# program to recognize my .vb file so that I can send variables to it through C# windows form methods. How can I get these 2 files to work together? do I need to include a using statement combined with a system method? What do you suggest?
Create a VB.NET new project
Add your VB file into it.
Compile the project and get the DLL from bin folder.
Add a reference to this DLL in your C# project.
Now you can access the functions of VB file.
Alternately, you can add both your C# and this new VB project in a single solution and add a reference to VB project in your C# project. This is the preferred solution from debugging point of view.
You may want to try freely available conversion tools that can convert your VB.NET code to C# code (and vice versa) that will get you rid of all of the above. I regularly use the excellent conversion tool called Econ NetVert available here.
I just noted that you have added VB6 as one of the tags in your question. Is the code in question in VB6? If so, you may first need to upgrade it to VB.NET. I know there was a wizard in VS2003 that could do this for you. Not sure if there's any other equivalent tool or method in VS2010 or VS2012 now-a-days.
Can anyone tell clearly about the usage of header files and namespaces in C#?
Because in C++ I was using ******.h files to read library functions. And when I saw some sample programs in C# they were missing, Can anyone tell me why?
I'm using C# to develop a custom tool for a CAD application. Whenever I use the appropriate function to open the file (CAD file), the compiler is giving me an error stating that the function names which I supply are not available in the context. Here what does meant by context?
When I opened the help file of that CAD application the function which is responsible for opening the file has bee mentioned under a header file called uf_part.h. But there is an namespace called NXOpen.
I used the namespace as using NXOpen in Visual Basic, isn't that enough? DO I need to supply that header file as well? If so, how?
C# is more "programmer friendly". When dealing with files of the same project, instead of manually specifying "header file" every time, it will go and look in all the project files for a match according to the namespace.
To understand this, do the following steps:
Start new project in Visual Studio. (No matter what type, WinForms or Console)
Right click the project and add new class.
In your main class note you can see the new class you just added, without adding any header.
How this is done? Simply by having the same namespace to both classes. The .NET engine is smart enough to link all those classes together.
Now, when it comes to external code meaning code sitting in a different DLL file the trick is to add reference to that DLL (in Studio --> Right click project --> Add reference --> Browse) then you need to specify you are going to use that DLL by adding a using statement on top:
using ExternalDllName.ExternalNamespace;
That's about it. Unlike C++ you don't need to have .h file as .NET will automatically search the referenced DLL files for a match.
There's no such thing as header file in .net, because all needed metadata is contained in referenced assembly itself.
Have you referenced needed assembly in you project?
Also please mind that there's no such thing as "function" in C#, only class methods (which means that you have to specify object or static class in you call).
Also: General Structure of a C# Program
Compilers for modern languages, such as C# or Java store within compiled files information on the classes and methods they contain, and this information can be used to check the correctness of calls made from one source file to another or to library classes.
When C was invented disk space, memory and CPU power were precious resources and this approach would not have been possible. Header files were introduced to allow the compiler to check that different source files conformed to the same interface. When C++ was invented the approach described above could have been possible, but I guess that it was chosen to stick to the C one for compatibility reasons.
I'm trying to create a re-useable MonoTouch library that contains Views defined in a xib, and Controller code written in Objective-C.
I have created a static Objective-C library that contains the relevant controller code with all the outlets declared.
A static *.a library obviously can't contain xib/nib data (if this is possible can someone please let me know), so I can't embed the xibs/nibs in this library.
I have created a 'MonoTouch Binding Project' that defines the relevant wrapper classes.
This is where I would ideally also embed the xibs/nibs, and have them included in the app bundle of any final project that links this dll.
Now looking at what a 'MonoTouch Library Project' does with xibs - it compiles it to a nib using ibtool, and then embeds it as a resource in the resultant library dll using the /res option of smcs. I'm assuming this is triggered because the xib file is marked with a "InterfaceDefinition" build action in the project.
However a 'MonoTouch Binding Project' has no "InterfaceDefinition" build action. Is this possible at all using a MonoTouch Binding Project?
I haven't tried it yet, but I'm assuming I could get it working manually by combining what the Library project does with ibtool and smcs /res and what the Binding Project does with btouch and smcs. But I'd rather avoid this, I'm enjoying the lack of Makefiles lately.
Xamarin/MonoTouch team - any plans to add this to Binding Projects in the future? Any way to force it to work currently?
Can you mix vb and c# files in the same project for a class library? Is there some setting that makes it possible?
I tried and none of the intellisense works quite right, although the background compiler seems to handle it well enough (aside from the fact that I, then, had 2 classes in the same namespace with the same name and it didn't complain).
We're trying to convert from VB to C# but haven't finished converting all the code. I have some new code I need to write, but didn't really want to make a new project just for it.
No, you can't. An assembly/project (each project compiles to 1 assembly usually) has to be one language. However, you can use multiple assemblies, and each can be coded in a different language because they are all compiled to CIL.
It compiled fine and didn't complain because a VB.NET project will only actually compile the .vb files and a C# project will only actually compile the .cs files. It was ignoring the other ones, therefore you did not receive errors.
Edit: If you add a .vb file to a C# project, select the file in the Solution Explorer panel and then look at the Properties panel, you'll notice that the Build Action is 'Content', not 'Compile'. It is treated as a simple text file and doesn't even get embedded in the compiled assembly as a binary resource.
Edit: With asp.net websites you may add c# web user control to vb.net website
Well, actually I inherited a project some years ago from a colleague who had decided to mix VB and C# webforms within the same project. That worked but is far from fun to maintain.
I decided that new code should be C# classes and to get them to work I had to add a subnode to the compilation part of web.config
<codeSubDirectories>
<add directoryName="VB"/>
<add directoryName="CS"/>
</codeSubDirectories>
The all VB code goes into a subfolder in the App_Code called VB and the C# code into the CS subfolder. This will produce two .dll files. It works, but code is compiled in the same order as listed in "codeSubDirectories" and therefore i.e Interfaces should be in the VB folder if used in both C# and VB.
I have both a reference to a VB and a C# compiler in
<system.codedom>
<compilers>
The project is currently updated to framework 3.5 and it still works (but still no fun to maintain..)
You can not mix vb and c# within the same project - if you notice in visual studio the project files are either .vbproj or .csproj. You can within a solution - have 1 proj in vb and 1 in c#.
Looks like according to this you can potentially use them both in a web project in the App_Code directory:
http://pietschsoft.com/post/2006/03/30/ASPNET-20-Use-VBNET-and-C-within-the-App_Code-folder.aspx
It might be possible with some custom MSBuild development. The supplied .targets force the projects to be single language - but there's no runtime or tooling restriction preventing this.
Both the VB and CS compilers can output to modules - the CLR's version of .obj files. Using the assembly linker, you could take the modules from the VB and CS code and produce a single assembly.
Not that this would be a trival effort, but it probably would work.
Walkthrough: Using Multiple Programming Languages in a Web Site Project http://msdn.microsoft.com/en-us/library/ms366714.aspx
By default, the App_Code folder does not allow multiple programming languages. However, in a Web site project you can modify your folder structure and configuration settings to support multiple programming languages such as Visual Basic and C#. This allows ASP.NET to create multiple assemblies, one for each language. For more information, see Shared Code Folders in ASP.NET Web Projects. Developers commonly include multiple programming languages in Web applications to support multiple development teams that operate independently and prefer different programming languages.
Yes its possible.adding c# and vb.net projects into a single solution.
step1: File->Add->Existing Project
Step2: Project->Add reference->dll or exe of project which u added before.
step3: In vb.net form where u want to use c# forms->import namespace of project.
Although Visual Studio does not support this (you can do some tricks and get MSBuild to compile both, but not from within Visual Studio), SharpDevelop does. You can have both in the same solution (as long as you are running Visual Studio Professional and above), so the easiest solution if you want to keep using Visual Studio is to seperate your VB code into a different project and access it that way.
Why don't you just compile your VB code into a library(.dll).Reference it later from your code and that's it. Managed dlls contain MSIL to which both c# and vb are compiled.
Right-click the Project. Choose Add Asp.Net Folder.
Under The Folder, create two folders one named VBCodeFiles and the Other CSCodeFiles
In Web.Config add a new element under compilation
<compilation debug="true" targetFramework="4.5.1">
<codeSubDirectories>
<add directoryName="VBCodeFiles"/>
<add directoryName="CSCodeFiles"/>
</codeSubDirectories>
</compilation>
Now, Create an cshtml page.
Add a reference to the VBCodeFiles.Namespace.MyClassName using
#using DMH.VBCodeFiles.Utils.RCMHD
#model MyClassname
Where MyClassName is an class object found in the namespace above.
now write out the object in razor using a cshtml file.
<p>#Model.FirstName</p>
Please note, the directoryName="CSCodeFiles" is redundant if this is a C# Project and the directoryName="VBCodeFiles" is redundant if this is a VB.Net project.
I don't see how you can compile a project with the C# compiler (or the VB compiler) and not have it balk at the wrong language for the compiler.
Keep your C# code in a separate project from your VB project. You can include these projects into the same solution.
You need one project per language. I'm quite confident I saw a tool that merged assemblies, if you find that tool you should be good to go. If you need to use both languages in the same class, you should be able to write half of it in say VB.net and then write the rest in C# by inheriting the VB.net class.
At the risk of echoing every other answer, no, you cannot mix them in the same project.
That aside, if you just finished converting VB to C#, why would you write new code in VB?
For .net 2.0 this works. It DOES compile both in the same project if you create sub directories of in app code with the related language code. As of yet, I am looking for whether this should work in 3.5 or not though.
As others have said, you can't put both in one project. However, if you just have a small piece of C# or VB code that you want to include in a project in the other language, there are automatic conversion tools. They're not perfect, but they do most things pretty well. Also, SharpDevelop has a conversion utility built in.
No, not in the same project.but you can use them in the same solution.
though you need to take care that your code is CLS compliant. That means you must not have used such functionality/feature that is not understand by other language. For example VB does not understand unsigned ints.
In our scenario, its a single VB.NET project (Windows Desktop application) in a single solution. However we wanted to take advantage of C# features like signed/unsigned integers and XML literals and string features in VB.NET. So depending on the features, at runtime we build the code file, compile using respective Rosalyn compiler (VB/CS) into DLL and dynamically load into current assembly. Of course we had to work on delinking, unloading, reloading, naming etc of the dynamic DLLs and the memory management were we largely used dynamic GUID for naming to avoid conflict.
It works fine where app user may connect to any DB from our desktop app, write SQL query, convert the connection to LINQ connection and write LINQ queries too which all requires dynamic building of source code, compiling into DLL and attaching to current assembly.
Yes, You can add both of the file in web site only.If the project is a web application it will not allow different type of file.