-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMount.ps1
88 lines (75 loc) · 2.64 KB
/
Mount.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<#
.SYNOPSIS
Helps to mount GitHub repo to your machine
.DESCRIPTION
It creates a symbolic link into Metadata folder of Dynamics 365 for Operations.
.COMPANY
Arbela Technologies Corp.
#>
if (Test-Path -Path K:\AosService)
{
$LocalDeploymentFolder = "K:\AosService"
}
elseif (Test-Path -Path C:\AosService)
{
$LocalDeploymentFolder = "C:\AosService"
}
elseif (Test-Path -Path E:\AosService)
{
$LocalDeploymentFolder = "E:\AosService"
}
elseif (Test-Path -Path J:\AosService)
{
$LocalDeploymentFolder = "J:\AosService"
}
else
{
throw "Cannot find the AOSService folder in any known location"
}
Write-Host "Using $LocalDeploymentFolder as the deployment folder"
$LocalPackagesFolder = Join-Path $LocalDeploymentFolder "PackagesLocalDirectory"
if (Get-Process devenv -ErrorAction SilentlyContinue) {
throw "Visual studio is running! Please close VS and run the script again."
}
# Install d365fo.tools if needed
if (Get-Module -ListAvailable -Name "d365fo.tools") {
Write-Host "Importing d365fo.tools"
Import-Module "d365fo.tools"
}
else {
Write-Host "Installing d365fo.tools"
Install-PackageProvider nuget -Scope CurrentUser -Force -Confirm:$false
Install-Module d365fo.tools -AllowClobber -SkipPublisherCheck -Force -Confirm:$false
}
Write-Host "Stopping D365FO environment"
Stop-D365Environment
# Get the list of models to junction
$ModelsToJunction = Get-ChildItem "$PSScriptRoot\..\Metadata\"
Write-Host "Enabling editing of the following models:" $ModelsToJunction
foreach ($Model in $ModelsToJunction)
{
$LocalModelPath = Join-Path $LocalPackagesFolder $Model
$RepoPath = Join-Path "$PSScriptRoot\..\Metadata" $Model
if (!(Test-Path $LocalModelPath -PathType Container))
{
Write-Host "Creating model folder: " $LocalModelPath
New-Item -ItemType Directory -Force -Path $LocalModelPath
}
$RepoSubfolders = Get-ChildItem $RepoPath
foreach ($RepoSubfolder in $RepoSubfolders)
{
$LocalSubfolderPath = Join-Path $LocalModelPath $RepoSubfolder
$RepoSubfolderPath = Join-Path $RepoPath $RepoSubfolder
if (Test-Path $RepoSubfolderPath -PathType Container)
{
# Use CMD and rmdir since Powershell Remove-Item tries to recurse subfolders
Write-Host "Removing existing $($Model)\$($RepoSubfolder) source code"
cmd /c rmdir /s /q $LocalSubfolderPath
# Create new symbolic links
Write-Host "Creating new symbolic link for $($Model)\$($RepoSubfolder)"
New-Item -ItemType:SymbolicLink -Path:$LocalSubfolderPath -Value:$RepoSubfolderPath
}
}
}
Write-Host "Starting D365FO environment"
Start-D365Environment