Adding C#-Code to VB-Project in VS 2005 without using DLL

S

Sven Rutten

Hello

Actually I want to add some C#-Code to a VB.NET-Project in VS 2005.
Normally I creating a DLL and importing that from the VB-Project.

But as I am coding something for a Smart Device (PocketPC), I dont want to
distribute multiple files, I'd like to distribute a single EXE file.

I've learned that I can, since VS 2005, add C#-Code to a VB Project.
I can add it, but not use it. What am I doing wrong?

Thanks

Sven
 
S

Stephany Young

Seeing as how you have learned that you can, since VS 2005, add C#-Code to a
VB Project, would you please be so kind as to enlighten us. We would be most
interested.
 
S

Sven Rutten

Hi Stephany

An Expert from experts-exchange.com told me so, but I cannot get it to
work...

Sven
 
S

Sven Rutten

Actually he's the #1 ranked there :)
But it's possible that I have misunderstood his answer...
 
H

Herfried K. Wagner [MVP]

Stephany Young said:
Seeing as how you have learned that you can, since VS 2005, add C#-Code to
a VB Project, would you please be so kind as to enlighten us. We would be
most interested.

You actually cannot, except in Web projects in which you can use different
languages in different script blocks and pages.
 
H

Herfried K. Wagner [MVP]

Stephany Young said:
So, what did he ACTUALLY tell you?

Well, maybe he was told that "it's possible to add C# code to a VB 2005
project", which is basically not wrong but on the other must not be
generalized.
 
R

RobinS

Can't you have a solution that has multiple projects, and the projects can
be in different languages?

Robin S.
 
S

Stephany Young

You're right it must not be generalised.

Until the OP tells us what he was told we cannot determine if it was right,
wrong or indifferent.
 
S

Stephany Young

Yes, of course you can. But references to the projects at design-time are
really 'smart' references to the compiled assemblies of those projects, in
that they know what and where the assenblies will be when thay are compiled.


RobinS said:
Can't you have a solution that has multiple projects, and the projects can
be in different languages?

Robin S.
 
B

BK

Although I'm not an expert, I do have a simple solution for you. Add
the C# code to it's own assembly class, compile the dll as you stated
you were already familiar with, and then use ILMerger to merge the 2
assemblies (the VB and C# outputs) into one final assembly.
 
R

rowe_newsgroups

I know this is slightly off topic, but I'm curious - since both vb and
c# compile to msil, why couldn't the ide use a preprocessor to support
different languages in the same file?

Something like:

#Visual Basic
Public Sub VBFoo()
...
End Sub
#End Visual Basic

#CSharp
public void CSharpFoo( )
{
...
}
#End CSharp

Thanks,

Seth Rowe
 
A

aaron.kempf

C# was never invented.

that is the best strategy; make those C# dorks use a real language.
 
M

Michael D. Ober

Seth,

Why don't you submit this to MS. This, at least on the surface, sounds like
a good idea.

Mike Ober.

rowe_newsgroups said:
I know this is slightly off topic, but I'm curious - since both vb and
c# compile to msil, why couldn't the ide use a preprocessor to support
different languages in the same file?

Something like:

#Visual Basic
Public Sub VBFoo()
...
End Sub
#End Visual Basic

#CSharp
public void CSharpFoo( )
{
...
}
#End CSharp

Thanks,

Seth Rowe
 
S

Stephany Young

Now there's a question and a half Seth :)

Have you finished the preprocessor yet? :)

How would you envisage it resolving something like:

#Visual Basic

Public Class Foo

#End Visual Basic

#Visual Basic

Public X As Integer

Public Sub VBFoo

x += 1

End Sub

#End Visual Basic

#CSharp

public int x;

public void CSharpFoo()
{
x++;
}

#CSharp

#Visual Basic

End Class

#End Visual Basic

In VB.NET, variable names are case-insensitive, so, logically the dummy
would be spat because VB.Net can;t handle 2 variables with the same name
having the same scope.

In C#, however, variable names are case-sensitive, so, X and x declared
having the same scope is perfectly legal.

The point here is that such a preprocessor, to be of any value would need to
break the rules of one language to allow the rules of the other language,
and, immediately, that need negates any value that such a preprocessor might
have.


rowe_newsgroups said:
I know this is slightly off topic, but I'm curious - since both vb and
c# compile to msil, why couldn't the ide use a preprocessor to support
different languages in the same file?

Something like:

#Visual Basic
Public Sub VBFoo()
...
End Sub
#End Visual Basic

#CSharp
public void CSharpFoo( )
{
...
}
#End CSharp

Thanks,

Seth Rowe
 
R

rowe_newsgroups

Now there's a question and a half Seth :)
Have you finished the preprocessor yet? :)

Finished? I haven't even started! (and probably won't)

:)
How would you envisage it resolving something like:
<snip>

Good point Stephany, I didn't really think it through - it was just a
thought that I had while reading this thread. Perhaps a class level
attribute that declares the entire class contents in a certain
language would resolve these issues, but that kind of defeats the
purpose (not to mention the "coolness" factor) doesn't it?.

By the way, how exactly would one find how to go about writing
something like this? Also, unless you rewrite the ide you would
probably lose intellisense and many other special features/keywords,
not to mention the error checking.

Thanks,

Seth Rowe
 
A

aaron.kempf

I just reccomend using Dreamweaver; and a single language

Avoid unnecessary complexities.

C# was _NEVER_INVENTED_ that is my strategy
until MS takes VB seriously they can lick my nuts
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top