您的位置:首页
Microsoft Visual Studio 2017 for Mac Preview 下载+安装+案例Demo
2016-11-26 12:33
916 查看
0. 前言:
工作原因,上下班背着我的雷神,一个月瘦了10斤,扛不住了,就把我的Mac放在公司。Mac之前为了运行VS,还买了一个PD虚拟机。。。
现在,我终于喝到鸡汤了——随着Visual Studio 2017的发布,for Mac的版本也诞生了、
下载地址大家可以去visualstudio官网下载,不过可能会有点儿慢,我上传了百度云。文章最后提供下载。
Mac的安装一贯很简单,装载镜像,拽到App中就可以了,这里为照顾新手,简单说一下过程:
【PS:也是够了,写这篇文章,浏览器崩了N次。重写了多少遍。=_=】
1. 在线安装器
下载得到VisualStudioforMacPreviewInstaller.dmg,大小23.9MB,这个是安装程序,说白了就是在线安装的。(文章结尾有下载)
双击镜像载入:
using System; using System.Configuration; using System.Data.SqlClient; namespace HelloWorld { class MainClass { public static void Main(string[] args) { string connStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; string sql = "select name from sysobjects"; SqlConnection conn = null; SqlDataReader reader = null; try { conn = new SqlConnection(connStr); conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); reader = comm.ExecuteReader(System.Data.CommandBehavior.CloseConnection); while (reader.Read()) { Console.WriteLine(reader["name"]); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (reader != null) reader.Close(); if (conn != null) conn.Close(); } } } }
ADO.NET测试代码
运行结果如下:
哈哈。有点儿意思 我的哥~
5. 测试ASP.NET MVC
趁热打铁,继续搞。右键解决方案,添加项目:
选择Other - ASP.NET MVC Project,点击Next下一步:
然后配置项目,选择是否创建WebAPI和单元测试,然后Next:
然后配置项目名称、路径等,然后点击Create即可创建:
创建完成之后,本来以为完事儿了,可是却弹出一个提示:
大概意思也就是说,项目需要下列这些玩意儿,你需要点击接受安装,才能完事儿。
没招,点呗,不然MVC相关的东西,例如Controller等都用不了。
点击Accept,上面显示Adding Packages...(正在添加组件):
稍等十秒左右,提示Packages successfully added.(添加完成):
大概看一下右侧的项目结构,同样的,和咱们平时的项目结构无异。
Controllers中是控制器,Views是视图,Models是模型,Scripts是脚本,。。。不用说了吧。
所以说,上手还是挺快的,呵呵。
直接点击运行,看一下效果:
呵呵,有点儿意思。。
在Models中添加User模型类:
using System; namespace HelloWorldMVC { public class User { public int Id { get; set; } public string Name { get; set; } public string Email { get; set; } } }
修改Controllers/HomeController.cs控制器代码,创建User数组并存入ViewBag中:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Ajax; namespace HelloWorldMVC.Controllers { public class HomeController : Controller { public ActionResult Index() { var users = new[] { new User(){ Id=1001, Name="张董", Email="778078163@qq.com" }, new User(){ Id=1002, Name="卡特琳娜", Email="katelinna@qq.com" }, new User(){ Id=1003, Name="盲僧", Email="mangseng@qq.com" }, new User(){ Id=1004, Name="莫甘娜", Email="moganna@qq.com" }, new User(){ Id=1005, Name="赏金", Email="shangjin@qq.com" } }; ViewBag.Users = users; return View(); } } }
修改Views/Home/Index.cshtml代码,显示刚刚存入的数组信息:
@if(ViewBag.Users==null) { <p>暂无资料。</p> } else { <table> <thead> <tr> <th>编号</th> <th>姓名</th> <th>邮箱</th> </tr> </thead> <tbody> @foreach(var item in ViewBag.Users) { <tr> <td>@item.Id</td> <td>@item.Name</td> <td>@item.Email</td> </tr> } </tbody> </table> }
点击运行:
哎呦我XXXX。打开Views/Shared/Layout.cshtml,果然,设置编码格式,添加meta修改如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>@ViewBag.Title</title> </head> <body> @RenderBody() </body> </html>
再次运行:
OK,完事儿~
5. 软件下载
在线安装+VS安装程序打包下载6. 结尾
哈哈,到此,案例都测试完了,感觉还不错。只是有一点,貌似自带的没有窗体应用程序。。。
好了,各位可以自己玩玩,有啥问题下面留言 咱们一起交流交流感情。哈哈。
相关文章推荐
- Microsoft Visual Studio 2017 for Mac Preview 下载+安装+案例Demo
- Microsoft Visual Studio 2017 for Mac Preview 下载+安装+案例Demo
- Microsoft Visual Studio 2017 for Mac Preview安装使用案例分享
- Microsoft Visual Studio 2017 for Mac Preview安装使用案例分享
- Microsoft Visual Studio 2017 for Mac Preview 的一些问题
- Microsoft Silverlight Tools Beta 1 for Visual Studio 2008安装失败的解决方法
- Microsoft Silverlight Tools Beta 1 for Visual Studio 2008 下载地址
- Microsoft Visual Studio 2015 下载、注册、安装过程、功能列表、问题解决
- Microsoft Silverlight Tools Beta 1 for Visual Studio 2008安装失败的解决方法之二
- Web Part Templates for Microsoft Visual Studio .NET--下载地址
- 安装Microsoft Visual Studio 2005 Extensions for Windows Workflow Foundation的工具箱控件丢失问题解决~~
- 微软测试版Visual Studio for Mac下载
- 安装 Microsoft Silverlight Tools Alpha for Visual Studio 2008 Beta 2 后, 新建 Silverlight 工程后, 找不到一堆引用的解决办法.
- Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System 正式版本下载
- UnityVS(Visual Studio Tools For Unity)的下载、安装与使用
- Microsoft Visual Studio 2015 下载、注册、安装过程、功能列表、问题解决
- Microsoft® Silverlight™ 3 Tools for Visual Studio 2008 SP1(中文)安装记
- Microsoft Silverlight Tools Beta 2 for Visual Studio 2008 下载地址
- Visual Studio for Mac Preview离线下载安装
- Microsoft Silverlight Tools Beta 2 for Visual Studio 2008 中文版下载