Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#how to run functions -
$WWI_OLTP = "C:\WWI_SSDT\wwi-ssdt"
$WWI_OLTP_SLN = Join-Path $WWI_OLTP "\WideWorldImporters.sqlproj"
$WWI_OLTP_DAC = Join-Path $WWI_OLTP "\Microsoft.Data.Tools.Msbuild\lib\net46"
Install-MicrosoftDataToolsMSBuild -WorkingFolder $WWI_OLTP -NugetPath $PSScriptRoot
Install-MicrosoftDataToolsMSBuild -WorkingFolder $WWI_DW -NugetPath $PSScriptRoot
Invoke-MsBuildSSDT -DatabaseSolutionFilePath $WWI_OLTP_SLN -DataToolsFilePath $WWI_OLTP_DAC
Invoke-MsBuildSSDT -DatabaseSolutionFilePath $WWI_DW_SLN -DataToolsFilePath $WWI_DW_DAC
function Install-MicrosoftDataToolsMSBuild {
param ( [string] $WorkingFolder,
[String] $NugetPath
, [string] $DataToolsMsBuildPackageVersion
)
if (-Not $WorkingFolder) {
Throw "Working folder needs to be set. Its blank"
}
Write-Verbose "Verbose Folder (with Verbose) : $WorkingFolder" -Verbose
Write-Verbose "DataToolsVersion : $DataToolsMsBuildPackageVersion" -Verbose
Write-Warning "If DataToolsVersion is blank latest will be used"
$NugetExe = "$NugetPath\nuget.exe"
if (-not (Test-Path $NugetExe)) {
Write-Error "Cannot find nuget at path $NugetPath\nuget.exe"
exit 1
}
write-warning "At least .NET Framework 4.6.1 needs to be installed on this machine to use Microsoft.Data.Tools.Msbuild." -verbose
$nugetInstallMsbuild = "&$NugetExe install Microsoft.Data.Tools.Msbuild -ExcludeVersion -OutputDirectory $WorkingFolder"
if ($DataToolsMsBuildPackageVersion) {
$nugetInstallMsbuild += "-version '$DataToolsMsBuildPackageVersion'"
}
Write-Host $nugetInstallMsbuild -BackgroundColor White -ForegroundColor DarkGreen
Invoke-Expression $nugetInstallMsbuild
$SSDTMSbuildFolder = "$WorkingFolder\Microsoft.Data.Tools.Msbuild\lib\net46"
if (-not (Test-Path $SSDTMSbuildFolder)) {
$SSDTMSbuildFolder = "$WorkingFolder\Microsoft.Data.Tools.Msbuild\lib\net40"
if (-not (Test-Path $SSDTMSbuildFolder)) {
Throw "It appears that the nuget install hasn't worked, check output above to see whats going on"
}
}
}
function Invoke-MsBuildSSDT {
param ( [string] $DatabaseSolutionFilePath
, [string] $DataToolsFilePath)
$msbuild = "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
if (-not (Test-Path $msbuild)) {
Write-Error "No MSBuild installed. "
Throw
}
$arg1 = "/p:tv=14.0"
$arg2 = "/p:SSDTPath=$DataToolsFilePath"
$arg3 = "/p:SQLDBExtensionsRefPath=$DataToolsFilePath"
$arg4 = "/p:Configuration=Debug"
Write-Host $msbuild $DatabaseSolutionFilePath $arg1 $arg2 $arg3 $arg4 -ForegroundColor White -BackgroundColor DarkGreen
& $msbuild $DatabaseSolutionFilePath $arg1 $arg2 $arg3 $arg4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment