创建Windows虚拟机以创建.NET和IIS流浪者环境

时间:2016-06-08 14:56:54

标签: .net windows macos vagrant virtualbox

作为使用OS X的前端开发人员,与基于Windows的开发人员合作,我想创建一个包含Windows,IIS,.NET,SQL Server和Sitecore的开发环境。

目标是绕过创建静态HTML,CSS和JS文件,而是直接进入.NET和Sitecore中的视图和模型文件。使用Vagrant,我可以访问localhost开发环境,这将允许我登录Sitecore并在开发时查看前端。

我知道现在modern.ie的旧Microsoft Edge VMs网站可以提供良好的入门环境。使用Vagrant,我想在IIS中配置各种软件,如IIS,.NET,SQL Server和Sitecore。

如果不是现代VM,我相信这可以通过任何许可的Windows 10 Professional ISO来完成。我的目标是尽可能使用Vagrant自动执行此设置,以便在运行vagrant up之后,我有一个用于前端开发的现成开发环境。

我需要通过哪个流程来实现这一目标?

1 个答案:

答案 0 :(得分:1)

您应该查看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脚本安装软件。