开发者

Visual Studio: Best way to use multiple programming languages for a single application

I often find myself using several programming languages when making .NET applications. Usually C++/CLI for interop to legacy code and C# for the rest.

With the coming support for F# as a first-class language, I could see myself mixing that in as well.

But is the only way to use multiple language still to setup a project per language? Do Visual Studio 2010 have any improved support for this? Are there any other开发者_JAVA技巧 solutions out there?


I don't believe VS2010 supports multiple languages in a single project, if that's what your asking. I think that would be rather tricky, to be honest. You could have cyclic dependencies between the different languages, so you couldn't just invoke one compiler after another - they'd have to co-operate on a fairly deep level, I suspect. While I dare say it would be technically feasible, I think it would be more work than the value added.


I would really wonder what you are actually gaining by mixing so many languages for a single product. C# has some pretty damn good interop capabilities, and generally C++ is only needed for the most extreme cases. Outside of one instance back in the .NET 1.1 days where I needed to use Windows XP themes in my application, I have never needed to use C++ for interop.

As for F#, it is an awesome language, but I think it still has a niche place. Over the years, C# has grown to encompass the best of all worlds, including functional and dynamic language features. Unless you really need the raw functional power of F#, I think from a general programming standpoint, C# provides enough functional capabilities to meet your needs.

Make sure you are REALLY gaining benefit from mixing multiple languages like that. A benefit that outweighs the cost of increased project complexity, the requirement that developers understand all three languages, the added maintenance costs of utilizing three languages, etc. I think overall thats a pretty hard sell. Use one language if you can, and only resort to an alternative in the extreme cases where C# really, truly doesn't offer you a solution. If you are writing an application that really needs F#, write the whole thing in F#.

As for VS2010 supporting multiple languages per project, its not a feature that I have heard of. I think it would be extremely difficult to support such a thing in the UI, and confusing to boot. I haven't heard of any addins that offer that capability either, and I've used ReSharper, SlickEdit, etc.


There's a feature request for this. Until that is implemented, a hack described by Scott Hanselmann is worth considering. TL;DR: you create separate projects per language, but then use ILMerge (via MSBuild) to combine these into a single assembly file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜