From 170d77bf75e082be85087fc8791ff6561aa5b6c3 Mon Sep 17 00:00:00 2001 From: Andrey Shchekin Date: Fri, 11 Aug 2017 23:29:05 +1200 Subject: [PATCH] [gh-142, gh-111] Potential build fixes. Updated Insights to record the app name. --- .../Step8.RewriteAndCopyMainAssemblies.cs | 10 +++- #build/Build-RoslynBranchIfModified.ps1 | 55 ++++++++++--------- #build/Publish-All.ps1 | 2 +- #build/Publish-ToAzure.ps1 | 7 +++ .../ApplicationInsightsMonitor.cs | 7 ++- source/Server.Azure/AzureModule.cs | 2 + 6 files changed, 51 insertions(+), 32 deletions(-) diff --git a/#build/#tools/AssemblyResolver/Steps/Step8.RewriteAndCopyMainAssemblies.cs b/#build/#tools/AssemblyResolver/Steps/Step8.RewriteAndCopyMainAssemblies.cs index b29d7fb..b5da4fc 100644 --- a/#build/#tools/AssemblyResolver/Steps/Step8.RewriteAndCopyMainAssemblies.cs +++ b/#build/#tools/AssemblyResolver/Steps/Step8.RewriteAndCopyMainAssemblies.cs @@ -28,7 +28,7 @@ namespace AssemblyResolver.Steps { rewritten = true; } if (rewritten) { - WriteAssembly(assembly, targetPath); + WriteAssembly(assembly, targetPath, mainAssemblies); } else { Copy.File(assembly.Path, targetPath); @@ -37,7 +37,7 @@ namespace AssemblyResolver.Steps { } } - private static void WriteAssembly(AssemblyDetails assembly, string targetPath) { + private static void WriteAssembly(AssemblyDetails assembly, string targetPath, IImmutableDictionary mainAssemblies) { var assemblyName = assembly.Definition.Name; assemblyName.PublicKey = new byte[0]; assemblyName.PublicKeyToken = new byte[0]; @@ -49,6 +49,12 @@ namespace AssemblyResolver.Steps { resolver.RemoveSearchDirectory(defaultPath); } resolver.AddSearchDirectory(targetDirectoryPath); + resolver.ResolveFailure += (sender, reference) => { + var mainAssembly = mainAssemblies.GetValueOrDefault(reference.Name); + if (mainAssembly == null) + return null; + return mainAssembly.Definition; + }; assembly.Definition.Write(targetPath); } diff --git a/#build/Build-RoslynBranchIfModified.ps1 b/#build/Build-RoslynBranchIfModified.ps1 index ffc6d5a..06df1d5 100644 --- a/#build/Build-RoslynBranchIfModified.ps1 +++ b/#build/Build-RoslynBranchIfModified.ps1 @@ -9,7 +9,6 @@ Set-StrictMode -Version 2.0 $ErrorActionPreference = 'Stop' $ProgressPreference = "SilentlyContinue" # https://www.amido.com/powershell-win32-error-handle-invalid-0x6/ -# Note: Write-Host, Write-Error and Write-Warning do not function properly in Azure ."$PSScriptRoot\Setup-Build.ps1" $branchFsName = $branchName -replace '[/\\:_]', '-' @@ -37,13 +36,6 @@ if (Test-Path "$sourceRoot\Binaries") { Remove-Item "$sourceRoot\Binaries" -Recurse -Force } -Write-Output "Building '$branchName'..." - -$buildLogPath = "$(Resolve-Path "$sourceRoot\..")\$([IO.Path]::GetFileName($sourceRoot))-$branchFsName.build.log" -if (Test-Path $buildLogPath) { - Remove-Item $buildLogPath -} - function Build-Project( [Parameter(Mandatory=$true)][string[]] $candidateProjectPaths, [string] $msbuildArgs @@ -52,33 +44,42 @@ function Build-Project( if (!$projectPath) { throw New-Object BranchBuildException("Project not found: none of @($candidateProjectPaths) matched.", $buildLogPath) } - " $projectPath $msbuildArgs" | Out-Default - - $projectPath = "$sourceRoot\$projectPath" - " dotnet restore" | Out-Default - dotnet restore "$projectPath" >> "$buildLogPath" - " dotnet build" | Out-Default - Invoke-Expression ("dotnet build `"$projectPath`" $msbuildArgs >> `"$buildLogPath`"") + " msbuild $projectPath $msbuildArgs" | Out-Default + &$MSBuild $projectPath /m /p:Configuration=Release /p:DelaySign=false /p:SignAssembly=false /p:NeedsFakeSign=false /p:SolutionDir="$sourceRoot\Src" >> "$buildLogPath" if ($LastExitCode -ne 0) { throw New-Object BranchBuildException("Build failed, see $buildLogPath", $buildLogPath) } } -$standardArgs = "/p:RestorePackages=false /p:Configuration=Debug /p:DelaySign=false /p:SignAssembly=false /p:NeedsFakeSign=false /p:SolutionDir=`"$sourceRoot\Src`"" -Build-Project "Src\Compilers\Core\Portable\CodeAnalysis.csproj" $standardArgs -Build-Project "Src\Compilers\CSharp\Portable\CSharpCodeAnalysis.csproj" $standardArgs -Build-Project "src\Features\CSharp\Portable\CSharpFeatures.csproj" $standardArgs -Build-Project "Src\Tools\Source\CompilerGeneratorTools\Source\VisualBasicSyntaxGenerator\VisualBasicSyntaxGenerator.vbproj" $standardArgs -Build-Project "Src\Compilers\VisualBasic\Portable\BasicCodeAnalysis.vbproj" "$standardArgs /p:IldasmPath=`"$(Resolve-Path "$sourceRoot\..\..\!tools\ildasm.exe")`"" -Build-Project "src\Features\VisualBasic\Portable\BasicFeatures.vbproj" $standardArgs +Write-Output "Building '$branchName'..." -if (Test-Path "$sourceRoot\NuGet.config") { - Remove-Item "$sourceRoot\NuGet.config" +$buildLogPath = "$(Resolve-Path "$sourceRoot\..")\$([IO.Path]::GetFileName($sourceRoot))-$branchFsName.build.log" +if (Test-Path $buildLogPath) { + Remove-Item $buildLogPath } -robocopy "$sourceRoot\Binaries\Debug" "$artifactsRoot\Binaries\Debug" ` - /xd "$sourceRoot\Binaries\Debug\Exes" ` - /xd "$sourceRoot\Binaries\Debug\CompilerGeneratorTools" ` +Push-Location $sourceRoot +try { + if (!(Test-Path '.\Restore.cmd')) { + throw New-Object BranchBuildException("Build failed: Restore.cmd not found.", $buildLogPath) + } + Write-Output " .\Restore.cmd" + .\Restore.cmd >> "$buildLogPath" + + Build-Project "Src\Compilers\Core\Portable\CodeAnalysis.csproj" + Build-Project "Src\Compilers\CSharp\Portable\CSharpCodeAnalysis.csproj" + Build-Project "src\Features\CSharp\Portable\CSharpFeatures.csproj" + Build-Project "Src\Tools\Source\CompilerGeneratorTools\Source\VisualBasicSyntaxGenerator\VisualBasicSyntaxGenerator.vbproj" + Build-Project "Src\Compilers\VisualBasic\Portable\BasicCodeAnalysis.vbproj" + Build-Project "src\Features\VisualBasic\Portable\BasicFeatures.vbproj" +} +finally { + Pop-Location +} + +robocopy "$sourceRoot\Binaries\Release" "$artifactsRoot\Binaries\Release" ` + /xd "$sourceRoot\Binaries\Release\Exes" ` + /xd "$sourceRoot\Binaries\Release\CompilerGeneratorTools" ` /xd "runtimes" ` /mir /np diff --git a/#build/Publish-All.ps1 b/#build/Publish-All.ps1 index d2aebaa..189b0ba 100644 --- a/#build/Publish-All.ps1 +++ b/#build/Publish-All.ps1 @@ -123,7 +123,7 @@ try { Write-Output "Updating $branchesFileName..." Set-Content "$sitesRoot\$branchesFileName" $(ConvertTo-Json $branchesJson -Depth 100) - $brachesJsLocalRoot = "$sourceRoot\Web\wwwroot" + $brachesJsLocalRoot = "$sourceRoot\WebApp\wwwroot" if (!(Test-Path $brachesJsLocalRoot)) { New-Item -ItemType Directory -Path $brachesJsLocalRoot | Out-Null } diff --git a/#build/Publish-ToAzure.ps1 b/#build/Publish-ToAzure.ps1 index e526a0f..d823c27 100644 --- a/#build/Publish-ToAzure.ps1 +++ b/#build/Publish-ToAzure.ps1 @@ -37,6 +37,13 @@ if (!$webApp) { -ResourceGroupName $resourceGroupName ` -Name $webAppName ` -WebSocketsEnabled $true | Out-Null + Set-AzureRmWebApp ` + -ResourceGroupName $resourceGroupName ` + -Name $webAppName ` + -AppSettings @{ + SHARPLAB_WEBAPP_NAME = $webAppName + SHARPLAB_TELEMETRY_KEY = $env:SHARPLAB_TELEMETRY_KEY + } | Out-Null } else { Write-Output " Found web app $($webApp.Name)" diff --git a/source/Server.Azure/ApplicationInsightsMonitor.cs b/source/Server.Azure/ApplicationInsightsMonitor.cs index b6a79bc..8633059 100644 --- a/source/Server.Azure/ApplicationInsightsMonitor.cs +++ b/source/Server.Azure/ApplicationInsightsMonitor.cs @@ -10,9 +10,11 @@ using SharpLab.Server.Monitoring; namespace SharpLab.Server.Azure { public class ApplicationInsightsMonitor : IMonitor { private readonly TelemetryClient _client; + private readonly string _webAppName; - public ApplicationInsightsMonitor(TelemetryClient client) { + public ApplicationInsightsMonitor(TelemetryClient client, string webAppName) { _client = client; + _webAppName = webAppName; } public void Event(string name, IWorkSession session, IDictionary extras = null) { @@ -31,10 +33,11 @@ namespace SharpLab.Server.Azure { _client.TrackException(telemetry); } - private static void AddDefaultDetails(TTelemetry telemetry, IWorkSession session, IDictionary extras) + private void AddDefaultDetails(TTelemetry telemetry, IWorkSession session, IDictionary extras) where TTelemetry: ITelemetry, ISupportProperties { telemetry.Context.Session.Id = session?.GetSessionId(); + telemetry.Context.Properties.Add("Web App", _webAppName); if (extras == null) return; diff --git a/source/Server.Azure/AzureModule.cs b/source/Server.Azure/AzureModule.cs index 78295eb..39c5b4b 100644 --- a/source/Server.Azure/AzureModule.cs +++ b/source/Server.Azure/AzureModule.cs @@ -17,8 +17,10 @@ namespace SharpLab.Server.Azure { builder.RegisterInstance(new TelemetryClient(configuration)) .AsSelf(); + var webAppName = Environment.GetEnvironmentVariable("SHARPLAB_WEBAPP_NAME"); builder.RegisterType() .As() + .WithParameter("webAppName", webAppName) .SingleInstance(); } }