方法一: 安装官方出的Microsoft.Bcl.Async包
最新发布日期为 2014/4/12,版本1.0.168
(不支持VS2010)
1、解决方案-右键-管理解决方案的NuGet程序包
2、搜索Microsoft.Bcl.Async,点击安装
3、等待下载完成
4、点击我接受
5、发现引用下多出7个引用
方法二、
2011年微软出了async的预览版,当时使用async的方式如下
1、准备好Visual Studio 2010 + SP1,无论什么版本。
VS2010 SP1升级补丁: Microsoft Visual Studio 2010 Service Pack 1 官方离线下载版(ISO)1.48G地址: http://download.microsoft.com/download/E/B/A/EBA0A152-F426-47E6-9E3F-EFB686E3CA20/VS2010SP1dvd1.iso
2、把Visual Studio Async CTP下载下来,并安装。
3、建个项目,现在你已经可以使用async和await关键字了,而诸如
WebClient
下的DownloadStringTaskAsync
方法,则是在%MyDocument%Microsoft Visual Studio Async CTPSamplesAsyncCtpLibrary.dll
下定义的扩展方法。安装VS2010 SP1 升级程序
如果双击安装程序,出现的界面不是下面,而是标题出现XXX维护
则需要在注册表下,hkey_current_usersoftwaremicrosoftinstallerproducts
在Products下找到一个ProductName叫 Microsoft Visual Studio 2010 Service Pack 1的项,并删除掉项9AC087DE786021C34B9333962F4249F1
再次打开安装程序就正常了
安装完SP1后,打开弹框报错:未能正确加载 “Microsoft.Data.Entity.Design.BootstrapPackage.BootstrapPackage,”
reg query HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftVisualStudio10.0AutoLoadPackages{adfc4e66-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} reg query HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftVisualStudio10.0AutoLoadPackages{93694fa0-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} reg query HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftVisualStudio10.0Packages{7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /s reg query HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio10.0AutoLoadPackages{adfc4e66-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} reg query HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio10.0AutoLoadPackages{93694fa0-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} reg query HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio10.0Packages{7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /s reg query HKEY_CURRENT_USERSOFTWAREMicrosoftVisualStudio10.0_ConfigAutoLoadPackages{adfc4e66-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} reg query delete HKEY_CURRENT_USERSOFTWAREMicrosoftVisualStudio10.0_ConfigAutoLoadPackages{93694fa0-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} reg query HKEY_CURRENT_USERSOFTWAREMicrosoftVisualStudio10.0_ConfigPackages{7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /s reg delete HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftVisualStudio10.0AutoLoadPackages{adfc4e66-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /f reg delete HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftVisualStudio10.0AutoLoadPackages{93694fa0-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /f reg delete HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftVisualStudio10.0Packages{7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /va /f reg delete HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio10.0AutoLoadPackages{adfc4e66-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /f reg delete HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio10.0AutoLoadPackages{93694fa0-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /f reg delete HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio10.0Packages{7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /va /f reg delete HKEY_CURRENT_USERSOFTWAREMicrosoftVisualStudio10.0_ConfigAutoLoadPackages{adfc4e66-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /f reg delete HKEY_CURRENT_USERSOFTWAREMicrosoftVisualStudio10.0_ConfigAutoLoadPackages{93694fa0-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /f reg delete HKEY_CURRENT_USERSOFTWAREMicrosoftVisualStudio10.0_ConfigPackages{7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /va /f reg query HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftVisualStudio10.0AutoLoadPackages{adfc4e66-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} reg query HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftVisualStudio10.0AutoLoadPackages{93694fa0-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} reg query HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftVisualStudio10.0Packages{7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /s reg query HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio10.0AutoLoadPackages{adfc4e66-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} reg query HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio10.0AutoLoadPackages{93694fa0-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} reg query HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio10.0Packages{7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /s reg query HKEY_CURRENT_USERSOFTWAREMicrosoftVisualStudio10.0_ConfigAutoLoadPackages{adfc4e66-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} reg query delete HKEY_CURRENT_USERSOFTWAREMicrosoftVisualStudio10.0_ConfigAutoLoadPackages{93694fa0-0397-11d1-9f4e-00a0c911004f} /v {7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} reg query HKEY_CURRENT_USERSOFTWAREMicrosoftVisualStudio10.0_ConfigPackages{7A4E8D96-5D5B-4415-9FAB-D6DCC56F47FB} /s
将上述代码复制到cmd下即可~如果一般不行来两遍。