创建 Windows 个虚拟机以创建 .NET 和 IIS vagrant 环境
Creating Windows virtual machine to create .NET and IIS vagrant environment
作为使用 OS X 的前端开发人员,与基于 Windows 的开发人员一起工作,我想创建一个开发环境,其中包括 Windows、IIS、.NET、SQL 服务器和 Sitecore。
目标是绕过创建静态 HTML、CSS 和 JS 文件,而是直接进入 .NET 和 Sitecore 中的视图和模型文件。使用 Vagrant,我可以访问本地主机开发环境,这将允许我登录 Sitecore 并在我开发时查看前端。
我知道旧的 modern.ie site which is now Microsoft Edge VMs 可以提供良好的入门环境。使用 Vagrant,我想将 IIS、.NET、SQL Server 和 Sitecore 等各种软件配置到 VM 中。
如果不是 modern.ie 虚拟机,我相信这可以通过任何获得许可的 Windows 10 Professional ISO 来完成。我的目标是使用 Vagrant 尽可能地自动化此设置,以便在我 运行 vagrant up
之后,我有一个用于前端开发的现成开发环境。
我需要经过什么过程才能使它起作用?
您应该查看 shell 配置 provisioning。脚本在 vagrant up
期间是 运行 所以在你进入 Windows
之前
在您的 Vagrantfile 中,您将添加
......
config.vm.define "win_10" do |win10|
win10.vm.box = "windows_10"
win10.vm.provision "shell", path: "puppet/install_ariba/test/install_win_jdk.ps1"
win10.vm.provision "shell", path: "puppet/install_ariba/test/install_browsers.ps1"
......
install_browsers.ps1
看起来像
function LogWrite {
Param ([string]$logstring)
$now = Get-Date -format s
Add-Content $Logfile -value "$now $logstring"
Write-Host $logstring
}
function CheckLocation {
Param ([string]$location)
if (!(Test-Path $location)) {
throw [System.IO.FileNotFoundException] "Could not download to Destination $location."
}
}
function add-host([string]$ip, [string]$hostname) {
$hostsPath = "$env:windir\System32\drivers\etc\hosts"
$ip + "`t`t" + $hostname | Out-File -encoding ASCII -append $hostsPath
}
$Logfile = "C:\Windows\Temp\chrome-firefox-install.log"
$FF_VER="45.0.1";
$firefox_source = "https://download-installer.cdn.mozilla.net/pub/firefox/releases/$FF_VER/win32/en-US/Firefox%20Setup%20$FF_VER.exe"
$firefox_destination = "C:\Windows\Temp\firefoxinstaller.exe"
LogWrite "Starting to download files $firefox_source"
try {
LogWrite 'Downloading Firefox...'
(New-Object System.Net.WebClient).DownloadFile($firefox_source, $firefox_destination)
CheckLocation $firefox_destination
} catch [Exception] {
LogWrite "Exception during download. Probable cause could be that the directory or the file didn't exist."
LogWrite '$_.Exception is' $_.Exception
}
LogWrite 'Starting firefox install process.'
try {
Start-Process -FilePath $firefox_destination -ArgumentList "-ms" -Wait -PassThru
} catch [Exception] {
LogWrite 'Exception during install process.'
LogWrite '$_.Exception is' $_.Exception
}
LogWrite 'Update hostfile'
add-host "192.168.90.52" "pws.app"
LogWrite 'All done. Goodbye.'
在这个例子中,我下载并安装了特定版本的 FireFox 以及更新主机文件。网上有很多使用 powershell 脚本安装软件的例子。
作为使用 OS X 的前端开发人员,与基于 Windows 的开发人员一起工作,我想创建一个开发环境,其中包括 Windows、IIS、.NET、SQL 服务器和 Sitecore。
目标是绕过创建静态 HTML、CSS 和 JS 文件,而是直接进入 .NET 和 Sitecore 中的视图和模型文件。使用 Vagrant,我可以访问本地主机开发环境,这将允许我登录 Sitecore 并在我开发时查看前端。
我知道旧的 modern.ie site which is now Microsoft Edge VMs 可以提供良好的入门环境。使用 Vagrant,我想将 IIS、.NET、SQL Server 和 Sitecore 等各种软件配置到 VM 中。
如果不是 modern.ie 虚拟机,我相信这可以通过任何获得许可的 Windows 10 Professional ISO 来完成。我的目标是使用 Vagrant 尽可能地自动化此设置,以便在我 运行 vagrant up
之后,我有一个用于前端开发的现成开发环境。
我需要经过什么过程才能使它起作用?
您应该查看 shell 配置 provisioning。脚本在 vagrant up
期间是 运行 所以在你进入 Windows
在您的 Vagrantfile 中,您将添加
......
config.vm.define "win_10" do |win10|
win10.vm.box = "windows_10"
win10.vm.provision "shell", path: "puppet/install_ariba/test/install_win_jdk.ps1"
win10.vm.provision "shell", path: "puppet/install_ariba/test/install_browsers.ps1"
......
install_browsers.ps1
看起来像
function LogWrite {
Param ([string]$logstring)
$now = Get-Date -format s
Add-Content $Logfile -value "$now $logstring"
Write-Host $logstring
}
function CheckLocation {
Param ([string]$location)
if (!(Test-Path $location)) {
throw [System.IO.FileNotFoundException] "Could not download to Destination $location."
}
}
function add-host([string]$ip, [string]$hostname) {
$hostsPath = "$env:windir\System32\drivers\etc\hosts"
$ip + "`t`t" + $hostname | Out-File -encoding ASCII -append $hostsPath
}
$Logfile = "C:\Windows\Temp\chrome-firefox-install.log"
$FF_VER="45.0.1";
$firefox_source = "https://download-installer.cdn.mozilla.net/pub/firefox/releases/$FF_VER/win32/en-US/Firefox%20Setup%20$FF_VER.exe"
$firefox_destination = "C:\Windows\Temp\firefoxinstaller.exe"
LogWrite "Starting to download files $firefox_source"
try {
LogWrite 'Downloading Firefox...'
(New-Object System.Net.WebClient).DownloadFile($firefox_source, $firefox_destination)
CheckLocation $firefox_destination
} catch [Exception] {
LogWrite "Exception during download. Probable cause could be that the directory or the file didn't exist."
LogWrite '$_.Exception is' $_.Exception
}
LogWrite 'Starting firefox install process.'
try {
Start-Process -FilePath $firefox_destination -ArgumentList "-ms" -Wait -PassThru
} catch [Exception] {
LogWrite 'Exception during install process.'
LogWrite '$_.Exception is' $_.Exception
}
LogWrite 'Update hostfile'
add-host "192.168.90.52" "pws.app"
LogWrite 'All done. Goodbye.'
在这个例子中,我下载并安装了特定版本的 FireFox 以及更新主机文件。网上有很多使用 powershell 脚本安装软件的例子。