forked from ddiyteam/webapitemplate_netcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplatePrepare.ps1
73 lines (59 loc) · 3.35 KB
/
templatePrepare.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
#=============================================================================
# Powershell script prepares multi-project zip template
#
# Before runnig this script:
# - manually export all projects as project teplates in VisualStudio (Project->Export Template)
# - copy all exported zip files to template folder (near ps script)
#
# After runnig this script
# - add prepared multi-project zip template to vsix project as asset for build or simply copy zip file to visual studio template folder (%USERPROFILE%\Documents\Visual Studio 17\Templates\ProjectTemplates)
#=============================================================================
$folderPath = "template";
$baseName = "Service";
$projects = @("API", "BLL", "Configuration", "DAL.MySql", "DbUp.MySql", "BLL.Tests");
if(test-Path "${folderPath}\output")
{
Remove-Item -LiteralPath "${folderPath}\output" -Force -Recurse;
}
foreach ($project in $projects) {
$projectFullName = "${baseName}.${project}";
if(test-Path "${folderPath}\${projectFullName}.zip")
{
Expand-Archive "${folderPath}\${projectFullName}.zip" -DestinationPath "${folderPath}\output\${projectFullName}";
#replaces for others files
$files = Get-ChildItem "${folderPath}\output\${projectFullName}" *.* -Recurse -Exclude "MyTemplate.vstemplate", *.csproj | Where-Object { ! $_.PSIsContainer };
foreach ($file in $files)
{
(Get-Content $file.PSPath) |
Foreach-Object { $_ -replace " ${baseName}\.", ' $ext_safeprojectname$.' } |
Set-Content $file.PSPath;
(Get-Content $file.PSPath) |
Foreach-Object { $_ -replace '\$safeprojectname\$', "`$ext_safeprojectname`$.${project}" } |
Set-Content $file.PSPath;
}
#replaces for vstemplate file
$templateFile = Get-ChildItem "${folderPath}\output\${projectFullName}" "MyTemplate.vstemplate";
(Get-Content $templateFile.PSPath) |
Foreach-Object { $_ -replace "TargetFileName=`"${baseName}.", 'TargetFileName="$ext_safeprojectname$.' } |
Set-Content $templateFile.PSPath;
(Get-Content $templateFile.PSPath) |
Foreach-Object { $_ -replace "</TemplateData>", ' <Hidden>true</Hidden>
</TemplateData>' } |
Set-Content $templateFile.PSPath;
#replaces for csproj file
$csprojFile = Get-ChildItem "${folderPath}\output\${projectFullName}" *.csproj;
(Get-Content $csprojFile.PSPath) |
Foreach-Object { $_ -replace "${baseName}.", '$ext_safeprojectname$.' } |
Set-Content $csprojFile.PSPath;
#files renames
Rename-Item -Path "${folderPath}\output\${projectFullName}\MyTemplate.vstemplate" -NewName "${project}.vstemplate";
Write-Host "${projectFullName}.zip was successfully converted" -ForegroundColor green;
}else {
Write-Host "${projectFullName}.zip does not exists" -ForegroundColor red;
}
}
Copy-Item "assets\WebAPI.vstemplate" -Destination "${folderPath}\output"
Copy-Item "assets\Icon.png" -Destination "${folderPath}\output"
Write-Host "WebAPI.vstemplate was copied" -ForegroundColor green;
Compress-Archive -Path "${folderPath}\output\*" -CompressionLevel Optimal -DestinationPath "${folderPath}\output\WebAPI_Template"
Write-Host "Template was successfully archived" -ForegroundColor green;