Using async-await on .net 4 - c#

I'm currently starting to create an application that would profit a lot from C# 5's async-await feature. But I'm not sure which version of VS and of the async runtime to use.
Looking at OS popularity charts, I'll need to support Windows XP for another three years or so. It looks like .net 4.5 runs only on newer versions of Windows, so I need to target .net 4.0. The development machines use Windows 7, so using a newer version of VS is not a problem.
Now I need to first choose a compiler for doing this:
VS2010 with AsyncCTP
VS2012 Preview (and final once it arrives), setting the target to .net 4.0
Mono (Looks like 2.12 has async-await, I prefer/am used to VS over MonoDevelop as IDE)
Which one has fewer code-gen bugs? Looking at Jon Skeet's blog the VS2012 Preview uses a never code-generator than the CTP.
And more importantly which runtime to use?
Does VS2012 contain a redistributable async runtime for use with .net 4?
I managed to compile code, with the preview, by referencing the AsyncCTP runtime. But since the CTP has strange licensing conditions, that doesn't look like a good long term solution.
Or should I use a third party implementation? Perhaps mono has one?
For distributing the library I prefer simply putting the dll in the same directory as the application, instead of some kind of installer.
I'd also like it if my binaries would work without changes on mono+Linux/MacOS. So the runtime should either be compatible with whatever mono (2.12 probably) has built in, or allow use on non windows OSs.

Microsoft released the Async Targeting Pack (Microsoft.Bcl.Async) through Nuget as a replacement for the AsyncCTP.
You can read more about it here: http://blogs.msdn.com/b/bclteam/archive/2013/04/17/microsoft-bcl-async-is-now-stable.aspx.
You can read about the previous version here: http://blogs.msdn.com/b/lucian/archive/2012/04/24/async-targeting-pack.aspx.
As this pack is officially supported, I now believe the best option for targeting XP + async would be using Visual Studio 2012 + C#5 + Async Targeting Pack.
If you feel the need to target .NET 3.5 though, you can still use (my) AsyncBridge for .NET 3.5.

If you are open to considering other .Net languages, F# can solve your problem. It has had the async{} computation expression for years, and is backwards compatible even with .Net 2.0. Minimum requirement is Windows XP SP3. The runtime can be downloaded here.

It's possible to use the VS 12 beta to target .NET 4.0 using async/await.
You need to copy some code into your project that provides the types that the compiler relies on.
Details here
Edit: we've taken this technique and turned it into a open source library called AsyncBridge:
https://nuget.org/packages/AsyncBridge

If you want to be able to distribute your software, I think that the Mono solution is really your only option right now. You also say that you want the end result to run on Mono over Linux and OS X. Targeting Mono to begin with seems like the natural solution.
Your next issue is the IDE. MonoDevelop would obviously work well but you say you prefer Visual Studio.
Greg Hurlman created a profile to code against Mono 2.8 from Visual Studio. If you follow-up with him, he might be able to point you in the right direction for developing against Mono 2.11/2.12 in Visual Studio.
Of course, there is also Mono Tools for Visual Studio which is a commercial product. I assume that it is still being offered by Xamarin.
You might also be able to run the required 4.5 profile assemblies from Mono on top of .NET but I have not tried that. The 4.5 profile is a strict super-set of the 4.0 API. Perhaps give it a shot and report back.
EDIT: It looks like perhaps you can use the Visual Studio Async CTP in production now
Here is what it says on the download page:
Includes a new EULA for production use. Note - This license does not
constitute encouragement for you to use the CTP for your production
code. The CTP remains an unsupported and use-at-your-own-risk
Technology Preview. However, we’ve received many requests from
developers to use the CTP for production code, and so have changed the
license to allow that.

If you want to start distributing your software after MS releases C# 5.0, then you can start developing using AsycnCTP.
Otherwise I wouldn't recommend you to use it, as it is just CTP, not even a beta. It can be changed a lot close to the beta stage and to the release. It may be unstable, etc.
If you want to introduce easy async operations in your application I would recommend you to use Reactive Extensions and stuff built on top (Reactive UI, etc), it is just beautiul.
As for VS2012, it also contains the same Async CTP as far as I remember from my //Build/ tablet MS gave me on that conference.

Related

Can't install the project after added Prerequisites NET 4.6

I used Visual Installer project to deploy.
After I added .NET 4.6 components to my project and built it, I didn't got click to install option, to check this in Visual studio.
But after deleting this everything worked again.
Download Prerequisites: I would set the prerequisite to download from the vendor's web site - that is the first option of those 3 in your screen shot - at least in my English Visual Studio Setup Project. I don't read Russian / Cyrillic I am afraid. Those letters really look like an alien language :-).
Eliminate Embedded Prerequisites (for common runtimes): My rant about including the .NET framework is generally that what you include is 1) outdated in no time with all the security fixes (hence bloating your setup for no reason?) and 2) the new Windows OS versions are including .NET pre-installed outright (albeit perhaps not in the correct version). 3) .NET is also installed via Windows Update now - for home users (eventually, there is some delay in release), and 4) corporate packagers absolutely hate pulling packages apart to remove common runtimes since they have to use standard corporate packages for these runtimes and are not allowed to use the bundled ones. Just a report from those who receive vendor setups. Keep it simple. Prefer to document what your setup does? Providing simple Readme.txt or Deployment Info.pdf is good. Delivering a special setup for corporations and large scale deployment is another good way to do it (just a zip of prerequisites and the actual setup).
Launch Condition: A simple launch condition telling the user to install the .NET framework and what version might be enough, but maybe your "download from vendor site" is best?
.NET Runtime: As a side-note - and I guess this is well known for most - just pointing it out to whoever might read this: There have been way fewer versions of the .NET runtime (CLR) than is commonly perceived. There is the framework, and then there is the runtime. Please see .NET expert and overall computer expert Hans Passant's summary here (and the other answers on the page too). One more. Version 1.0 and 1.1 of the CLR would seem to be largely irrelevant by now?
Alternative Tools: I have long disliked Visual Studio Installer Projects. Just throwing in a link to alternative MSI tools.

Manually adding .NET 4.5 scripts to Unity: Potential issues?

I've recently had to some work in Unity that required classes only available in the later versions of .NET, which Unity does not yet support. I managed to download the very few scripts that I was missing and added it to my project and it seems to work fine. What I wanted to know is why can I not just take the entire .NET source and shove it into my projects? What are the implications of doing something like that?
EDIT: The scripts that I have added so far was the generic version of WeakReference as well as any dependencies that it needed (Contract in System.Diagnostics.Contract).
EDIT EDIT: I basically want to know why I can't simply just the C# class files found in the later versions of .NET to Unity, which uses an older version of .NET. Is it a software issue? Is it a hardware issue? Is it because Unity's system components were built in correspondence with the earlier version of .NET?
SHORT ANSWER:
Install the Visual Studio Tools for Unity (it should automatically get installed when you install Unity), when you do you can tell your .csproj in the "target framework" drop-down to target the special version of .NET Unity uses and you will only be able to compile dll's that have methods and types that Unity supports.
LONG ANSWER:
It is because Unity does not use the installed version of .NET on your computer. Unity uses Mono, and a very old version at that. This allows unity to be ran on multiple platforms and OSes. Because of that you can only use features that are in the supported version of Mono.
However, if you look at their roadmap the alpha build you will see
Scripting: C# Compiler Upgrade
Upgrade Mono C# compiler against our
current .Net 2.0 and 2.0 Subset profiles. Note that this is an upgrade
of the C# compiler only, not the full Mono runtime
Then further on in the "research" phase
Scripting: .NET Profile Upgrade
Upgrade .Net profile to 4.6 enabling access to the latest .Net functionality and APIs.
UPDATE:
You can get a experimental build that uses the 4.6 profile from the stickied post here.
Here are the notes for the 5.6.0b5 beta release
For this release, the Editor and the following players should be working:
Windows, OSX, Linux standalone
iOS with IL2CPP
Android with IL2CPP and Mono
Other platforms are known to not work yet, and are probably not worth installing.
Managed debugging via Visual Studio Tools for Unity or MonoDevelop is not supported in this release. If you want to use VSTU for
editing please use the special build linked at the bottom of this
post.
The compiler targets the C# 6 language.
The compiler by default will still target the .Net 4.6 framework profile.
Known issues
The Android/Mono build does not work properly with managed code stripping. Please disable managed code stripping for now.
For some projects, the Windows standalone player can crash on Windows 8.1. This is intermittent, so we would love to see any crash
reports or data about this
A similar question was answered before here. Like I described in your other question, you can "inject" newer stuff and use them, but sooner or later they'll backfire (e.g. can't compile to particular systems, can compile but cannot be published in whatever mobile store, surprisingly slow execution, huge builds, etc. Worst case your project will be compromised).
If you really cannot refactor the project you are working on and you feel you must use 'up-to-date technology', bear in mind the injected classes code must be data objects, means, not at all related to GameObjects.It is also adviced to derive from ScriptableObject when and where possible.EDIT: But I'd recommend what I told you earlier (refactor) or what the linked answer describes ('export' the code incompatible with mono/.net2.0 to an external dll and use it from there)

MonoDevelop in windows

Is there a version of Monodevelop that runs on Windows? If so where can I get it?
MonoDevelop officially supports Windows since 2.2. You can check the what's new in Monodevelop 2.2 or download the last release.
Windows Support
Windows now Officially Supported
Windows is now an officially supported
platform for running MonoDevelop. Many
Windows specific issues have been
fixed, and some add-ins such as
debugging and subversion support have
been written specifically for Windows.
Windows Installer
We are releasing a new Windows
Installer which includes almost all
you need to run MonoDevelop. The only
external dependency is gtk#, which is
provided in a separate installer.
It looks like you can build it and run it on Windows, but I don't think there is a binary download available yet. From the docs, here:
Does MonoDevelop work on Windows?
Yes. MonoDevelop can be built and run
on Mono on Windows, although it is
still unstable and some features may
not be available. We are currently
working on a Windows installer that
will be soon be available.
There are no precompiled binaries, so you'd have to build from source. Even then, there seems to be some stability issues running MonoDevelop on Windows (see here).
Some alternatives would be SharpDevelop and/or Visual Studio Express.
Update: MonoDevelop version 2.2 and higher officially supports Windows. You can get the latest version here: http://monodevelop.com/Download
There is currently no official release of Monodevelop for windows. After researching it a little bit, it seems that MonoDevelop was started as a port of SharpDevelop which is an open source .Net IDE for windows. Perhaps you may want to look into SharpDevelop and see if it meets your needs.
You can find out more information at the SharpDevelop website:
http://www.icsharpcode.net/OpenSource/SD/
You can specifically target the Mono framework when writing apps in SharpDevelop (something you can't do with Visual Studio Express). I should have pointed this out in my answer above. From the website:
SharpDevelop has the ability to
compile your code against previous
versions of Microsoft's .NET
Framework, Microsoft's Compact
Framework or Mono (an open source
implementation of the .NET Framework
sponsored by Novell) if they are
installed.
The easiest way now to get MonoDevelop is running openSUSE Linux under VirtualBox. It's really no so hard. You will get "real" linux system with Mono & MonoDevelop running on it without any issues. Hope this helps.
There is not currently binaries available for MonoDevelop for Windows. This is because it has not been tested and is extremely buggy. Ie: you will probably not get more a minute or two of use before it crashes. Hopefully with MD 2.0 now out, this is something we will soon have time to address.
Note that you do not need MonoDevelop to use Mono. You can use the same binaries produced from Visual Studio or SharpDevelop on Mono.

Feasibility of C# development with Mono

Recently, I came across Mono and MonoDevelop packages in Ubuntu linux. They claim to have a .NET runtime in accordance with CLI. Before installing the packages myself, I would like to know the following:
How powerful is Mono?
Can I develop GUI application for
linux like developing WinForm
applications for Windows.
Is MonoDevelop IDE compatible with Visual Studio IDE. Can I import VS 2008 solutions to MonoDevelop and work?
Does it support .NET 2.0 and above?
EDIT: Adding one more doubt
Is there any way to run the .NET exe (of a winform app) in Linux without building the cod e in linux? In fact I don't have the code for some of the small utilities I developed earlier and would like to run them in linux.
(Strange, markdown starts the enumeration with one, even though I began with 2...)
Yes, you can, but you're limited with 3rd-party components, because the internal implementation is different, and last time I checked (not very long ago), the Mono WinForms implementation made my test app look rather strange (owner-drawn list view). It is not really recommended, though Mono claims that it's now completely WinForms-2.0-compatible.
MonoDevelop is/was a SharpDevelop branch, with the latter having solution support. I don't know if MonoDevelop has. But the cool thing is, you can just develop with Visual Studio and run your compiled apps on Mono. And Mono is, by the way, also available for Windows.
Yes, it does, as far as the CLR goes. As Marc Gravell already wrote, the Windows Foundation libraries are missing, as are a few other (System.Management, for example). But things should mostly work, including ASP.NET 2.0. Mono's application portability guidelines are a good read on this.
1: pretty good, actually. Not all the full framework is there, so if you are writing code that should build on both MS .NET and mono, you need to build and test early against both platforms
4: yes - although things like WPF/WCF/WF (3.0) are missing or slimmed down
I don't know much about the development environment, since I use VSTS (on Windows) and just use a NANT script to do the build on mono...
Define "powerful".
Mono has a WinForms implementation to allow for some level of source compatibility. However, depending on your needs, you might want to use one of the Mono bindings for a Linux native framework, like Gtk# or Qyoto
Wouldn't know.
Depends on what parts of .NET you mean. C# the language seems to be pretty current, things get fuzzier the closer you get to the enterprisey features as was already mentioned.
To sum things up, if you'll be using Mono as a separate target platform, you're likely to have good results. If you want a no-code-changes-required .NET compatibility layer, less so.
Very powerful. There are no major bugs in the core implementation. It is not a science project. The deficiencies are mostly where you would expect, the newest APIs (Microsoft inherently has a first-mover advantage there).
Yes. We just finished a project where most of the GUI code was developed in WinForms on Windows. I was able to work on it using Ubuntu without major headaches. That said, this is one of the hardest parts of the API, and there are still issues. See http://mono-project.com/WinForms for details.
Don't know, as I don't use it.
Yes, though again, there may be some missing APIs in the runtime.
Note, I use Ubuntu Hardy (8.04).
Mono is mighty powerful. It has all the .Net muscle on a very strong open source skeleton.
When you say "develop GUI application for linux like developing WinForm applications for Windows" I understand that you are asking about a visual designer that will allow you to quickly create the UI. Yes, it is possible. MonoDevelop has Stetic - a built-in visual designer for Gtk#. There is also QyotoDevelop which enables QT support in MonoDevelop.
Yes, MonoDevelop natively supports VS project/solution file format. You can use the same code base to compile your app with VS in .Net on Windows and win MD in Mono on Linux.
Currently Mono supports C# 3.0 with some stuff beyond that already implemented and a lot in the pipeline.
Yes, in many cases it is possible to run a .Net compiled app in Mono, however with MonoDevelop's support for VS solutions it doesn't really matter. It takes as much as pressing F7 to rebuild the whole project, so the effort is really negligible. The best tool for checking if your application can run in Mono is MoMA.
Mono is very powerfull, sometimes even more powerfull than Microsoft's implementation. link text
Yes you can. Winforms 2.0 is supported
I believe so.
Yes it does. C# 3 is supported and just look at winforms and the asp.net implementation to see how much is supported from each of the projects. Look at http://mono-project.com
I use WinForms in mono. The 2.x releases are very good.
I develop forms in visual-studio on windows, and run them in Linux, with zero code changes. Yes, forms look a little different than on XP, but then again, an XP-themed GUI would look kind of strange in GNOME.
If you are just getting started, stick with WinForms, while you get comfortable with Mono/Linux. However at some point you might want to investigate GTK.

Can I write an app in the new version of Visual Studio and make it compatible with .NET Framework 1.1

I am a Web developer who spends 99% of his time in Linux, but I need to develop a super simple application with VB or possibly C# (.Net). The only version of Visual Studio I have is the most current free ones. There MIGHT be a copy of 2001 lying around somewhere. Anyways, the machine I need to develop this for is running Windows NT4. I cannot change this because another piece of software runs on that requires it.
Is there a way to develop an app with the new VS and keep it compatible with such an old version of the .Net framework (1.1)?
If nothing else I could install Perl on the machine and write a command line type script, but given the people that will be using it GUI would be better.
I don't believe you can target .Net 1.1 in Visual Studio 2008. Here's one of the developer's explanations, from a comment in this blog entry:
Visual Studio 2008 will not support targeting .Net Framework 1.1. This is something we really wanted to be able to support - since we know there are a lot of .NET developers working on .NET 1.1 applications. However, it would have been significantly more difficult to go back and support .NET 1.1 which was a substantially different runtime.
Thus, to fit in this release, the
decision ended up being either to not
support multitargeting at all - or to
support only targeting .NET2.0 and
greater. Because we really wanted
Visual Studio 2008 to be a great tool
for at least both .NET 3.0 and .NET
3.5 - we decided to put in the most multitargeting support we could fit in
this release.
Have you tried MSBee? This is an add-on to VS2005 (well, strictly speaking: MSBuild in 2.0), but it may well work with VS2008 too. Of course, you can always use the IDE to write code, and simply use MSBuild from the 2.0 folder to build...
Either way, if you target .NET 1.1, you can only use .NET 1.1 / C# 1.2 features.
Personally, I'd target 3.5SP1, using (if it needs to be free) C# Express 2008. (I've removed this since you need to target such an old OS)
You can use vs.net 2008 to write code that is able to run on .net v1.1 but the IDE won't give you any hints on what will work etc.
You will be stuck using inline asp.net for a model.
(or compile using the commandline tools)
There are a lot of examples using this method here:
http://www.learnasp.com/freebook/learn/
This code is all v1.1 except for the explicit naming of the v2 examples.

Categories

Resources