首页 技术 正文
技术 2022年11月14日
0 收藏 697 点赞 4,032 浏览 2569 个字

最近,一直在往.Net Core上迁移,随着工作的深入,发现.Net Core比.Net Framework好玩多了。不过目前还在windows下开发,虽然VisualStudio是宇宙第一神器,但是最近经常莫名其妙的重启,让我对它有些不放心了,干脆在MacOS搭建一个开发环境,还附带装13效果:)

  1. 首先安装.Net Core SDK
  2. 安装VS Code及插件
  3. 安装Git
  4. 配置Nuget源,推荐使用博客园的镜像
  5. 克隆代码,然后编译
  6. 由于涉及到跨域等问题,该项目必须使用域名地址寄宿
    public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls("http://project.domain.com:9000")
.UseIISIntegration()
.UseStartup<Startup>()
.Build(); host.Run();
}
}
  1. 因此需要手动设置host:打开Finder,Go -> Go to Folder: /private/etc/ 找到hosts文件,添加我们的域名解析(如下最后一行):
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1localhost
255.255.255.255broadcasthost
::1 localhost
127.0.0.1project.domain.com
  1. dotnet run跑一下,使用project.domain.com:9000访问

  2. 由于调用了其他项目的API,而在MacOS中没有部署,所以报错了。而其他项目目前还是没有迁移,所以只能开虚拟机寄宿他们。

  3. 我们使用VMWare Fusion运行Windows10,设置Windows的上网方式为NAT,这样还有个问题,那就是Windows的IP地址是动态分配的,所以下一步就是固定Windows的IP地址。

  4. 打开终端,进入/Library/Preferences/VMware Fusion/vmnet8,使用vi dhcpd.conf打开文件

subnet 192.168.199.0 netmask 255.255.255.0 {//子网掩码
range 192.168.199.128 192.168.199.254;//IP地址分布范围
option broadcast-address 192.168.199.255;//默认网关
option domain-name-servers 192.168.199.2;//DNS
option domain-name localdomain;
default-lease-time 1800; # default is 30 minutes
max-lease-time 7200; # default is 2 hours
option netbios-name-servers 192.168.199.2;
option routers 192.168.199.2;
}
host vmnet8 {
hardware ethernet 00:50:56:C0:00:08;
fixed-address 192.168.199.1;
option domain-name-servers 0.0.0.0;
option domain-name "";
option routers 0.0.0.0;
}

打开windows10的控制面板,设置当前的网络的属性中的TCP/IPV4的属性,根据上面的注释,依次填空,注意IP地址不能超过上面注释中的范围。

最后在Mac中ping一下虚拟机的地址,确认可以访问。

如此,就能固定虚拟机的IP地址了,现在只要把需要用到的项目的地址在Hosts文件中设置好即可。

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1localhost
255.255.255.255broadcasthost
::1 localhost
127.0.0.1project.domain.com
192.168.199.133 login.domain.com
192.168.199.133 common.domain.com

折腾了这么久,终于可以在Mac下愉快的玩耍了。


现在有个问题很尴尬,我们已经在hosts文件中,把域名指向了开发环境,那么我们自己要访问生产环境的话,还需要更改hosts,这时候就可以发挥shell脚本的功能了。

个人比较喜欢powershell,推荐各位童鞋尝试一下。

首先把/private/etc/hosts复制到~/Documents/shell/hosts/original/hosts,这个用于恢复正常环境,然后再复制一份到~/Documents/shell/hosts/modified/hosts,这一个用于开发环境。

然后再~/Documents/shell/下新建两个powershell脚本,如下:

Copy-Item /Users/当前用户名称/Documents/shell/hosts/modified/hosts /private/etc/hosts
Write-Host "It's workspace!"

保存为To_workspace.ps1

Copy-Item /Users/当前用户名称/Documents/shell/hosts/original/hosts /private/etc//hosts
Write-Host "It's relax time!"

保存为To_relaxtime.ps1

使用方式

切换到开发环境,打开终端,输入:powershell回车,把To_workspace.ps1直接拖进去回车。

同样的,把To_relaxtime.ps1拖进去回车就会恢复正常状态。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,146
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,618
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,461
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,236
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,871
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,953