Skip to content

Commit

Permalink
Reapply MSAL change from CattieCat/MSAL1208
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinjing Ma committed Jun 10, 2021
1 parent d16d6dc commit 4675e53
Show file tree
Hide file tree
Showing 72 changed files with 734 additions and 1,219 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.user
*.userosscache
*.sln.docstates
*.sln

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down Expand Up @@ -58,7 +59,6 @@ artifacts/
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
Expand Down
28 changes: 22 additions & 6 deletions src/Directory.Build.props → Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
***********************************************************************************************
-->
<Project>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<MinimumMSBuildVersion>16.8</MinimumMSBuildVersion>
<RestoreUseStaticGraphEvaluation>true</RestoreUseStaticGraphEvaluation>
<LangVersion>latest</LangVersion>
<RepoRoot>$(MSBuildThisFileDirectory)..\</RepoRoot>
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
<RepoTargets>$(RepoRoot)build\</RepoTargets>
<SourceRoot>$(RepoRoot)src\</SourceRoot>
<ScriptsRoot>$(RepoRoot)scripts\</ScriptsRoot>
<PowerShellExe Condition="'$(PowerShellExe)' == ''">%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe</PowerShellExe>
<PowerShellExe Condition="'$(PowerShellExe)' == ''">$(WINDIR)\System32\WindowsPowerShell\v1.0\powershell.exe</PowerShellExe>
<PowerShellExe Condition="!Exists('$(PowerShellExe)')">$(ProgramFiles)\PowerShell\7\pwsh.exe</PowerShellExe>
<PowerShellCommonArgs>-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted</PowerShellCommonArgs>
<LangName Condition="'$(LangName)' == ''">en-US</LangName>
</PropertyGroup>
Expand All @@ -37,10 +40,23 @@ Licensed under the MIT License.
<RepositoryUrl>https://github.com/Microsoft/powerbi-powershell</RepositoryUrl>
</PropertyGroup>

<Import Project="$(RepoTargets)Microsoft.PowerBI.CodeSign.targets" Condition="'$(NoSignTarget)' != 'true'"/>
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);*.binlog</DefaultItemExcludes>
</PropertyGroup>

<!-- Slngen -->
<PropertyGroup>
<SlnGenLaunchVisualStudio>true</SlnGenLaunchVisualStudio>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SlnGen" />
</ItemGroup>

<Import Project="$(RepoTargets)Microsoft.PowerBI.CodeSign.targets" Condition="'$(NoSignTarget)' != 'true' AND '$(MSBuildProjectFile)' != 'dirs.proj'"/>

<Import Project="$(RepoTargets)Microsoft.PowerBI.Build.targets" Condition="'$(NoBuildTarget)' != 'true'"/>
<Import Project="$(RepoTargets)Microsoft.PowerBI.Build.targets" Condition="'$(NoBuildTarget)' != 'true' AND '$(MSBuildProjectFile)' != 'dirs.proj'"/>

<Import Project="$(RepoTargets)Microsoft.PowerBI.Packaging.targets" Condition="'$(NoPackageTarget)' != 'true'"/>
<Import Project="$(RepoTargets)Microsoft.PowerBI.Packaging.targets" Condition="'$(NoPackageTarget)' != 'true' AND '$(MSBuildProjectFile)' != 'dirs.proj'"/>

</Project>
4 changes: 4 additions & 0 deletions Directory.Build.rsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-restore
-consoleLoggerParameters:Verbosity=Minimal;Summary;ForceNoAlign
-maxCpuCount
-IgnoreProjectExtensions:.sln
17 changes: 17 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Sdk Name="Microsoft.Build.CentralPackageVersions" />

<!-- Ensure developers are using a minimun supported version of VS -->
<Target Name="ValidateMinimumMsBuildVersion"
BeforeTargets="Restore;$(BuildDependsOn);Build;$(RebuildDependsOn);Rebuild;$(CleanDependsOn);Clean"
Condition=" '$(DesignTimeBuild)' != 'true' ">
<Error Text="Building this repository requires a minimun Visual Studio version of $(MinimumMSBuildVersion)" Condition="$(MSBuildVersion) &lt; $(MinimumMSBuildVersion)" />
</Target>

<Target Name="ValidatePowerShellExeExists"
BeforeTargets="Restore;$(BuildDependsOn);Build;$(RebuildDependsOn);Rebuild;$(CleanDependsOn);Clean"
Condition=" '$(DesignTimeBuild)' != 'true' ">
<Error Text="This repository requires either Windows PowerShell or PowerShell Core 7 to be installed (default location) to execute builds: $(PowerShellExe)" Condition="!Exists('$(PowerShellExe)')" />
</Target>
</Project>
File renamed without changes.
22 changes: 22 additions & 0 deletions Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Update="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Update="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Update="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Update="PowerShellStandard.Library" Version="7.0.0-preview.1" PrivateAssets="all" />
<PackageReference Update="Microsoft.PowerShell.SDK" Version="7.1.1" />
<PackageReference Update="Microsoft.PowerShell.Commands.Diagnostics" Version="7.1.1" />
<PackageReference Update="Microsoft.WSMan.Management" Version="7.1.1" />
<PackageReference Update="Microsoft.Rest.ClientRuntime" Version="2.3.11" />
<PackageReference Update="System.Net.Http" Version="4.3.3" />
<PackageReference Update="Microsoft.Identity.Client.Extensions.Msal" Version="2.16.8" GeneratePathProperty="true" />
<PackageReference Update="Microsoft.Identity.Client" Version="4.25.0" GeneratePathProperty="true" />
<PackageReference Update="Microsoft.PowerBI.Api" Version="2.14.0" />
<PackageReference Update="System.Runtime.Serialization.Json" Version="4.3.0" />
<PackageReference Update="Moq" Version="4.8.2" />
<PackageReference Update="platyPS" Version="0.9.0" />
<PackageReference Update="SlnGen" Version="2.2.30" PrivateAssets="all"/>
</ItemGroup>
</Project>
37 changes: 27 additions & 10 deletions build/Microsoft.PowerBI.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,36 @@ Licensed under the MIT License.
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.csproj' AND '$(Configuration)' == 'Debug' ">
<DebugType>portable</DebugType>
</PropertyGroup>

<ItemGroup Condition="'$(ReferenceWindowsAuthenticator)' == 'true'">
<ProjectReference Include="$(SourceRoot)Common\AzureADWindowsAuthenticator\AzureADWindowsAuthenticator.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<PrivateAssets>All</PrivateAssets>
</ProjectReference>
</ItemGroup>

<Target Name="CopyWindowsAuthenticator" AfterTargets="Build" Condition="'$(ReferenceWindowsAuthenticator)' == 'true'">
<Target Name="CopyMsalIfNeeded" AfterTargets="Build" DependsOnTargets="ResolvePackageAssets;ResolveAssemblyReferences">
<ItemGroup>
<WindowsAuthenticatorFiles Include="$(SourceRoot)Common\AzureADWindowsAuthenticator\bin\$(Configuration)\**\*" />
<MSALKnownPackageReferences Include="Microsoft.Identity.Client.Extensions.Msal" />
<MSALKnownPackageReferences Include="Microsoft.Identity.Client" />
</ItemGroup>

<FindInList CaseSensitive="false" List="@(PackageDependencies)" ItemSpecToFind="%(MSALKnownPackageReferences.Identity)">
<Output TaskParameter="ItemFound" ItemName="FoundMSALReferences"/>
</FindInList>

<Message Text="Found MSAL References: @(FoundMSALReferences)" Condition="'@(FoundMSALReferences)' != ''" Importance="High" />

<!-- If the project directly referenced MSAL packages, we could have used Include="$(PkgMicrosoft_Identity_Client)\lib\netcoreapp2.1\*.dll" but in situation of an indirect reference this wouldn't be available -->
<ItemGroup Condition="'@(FoundMSALReferences)' != ''">
<MsalPackageDefinitions Include="@(PackageDefinitions)" Condition="'%(Name)' == 'Microsoft.Identity.Client.Extensions.Msal'" />
<MsalPackageDefinitions Include="@(PackageDefinitions)" Condition="'%(Name)' == 'Microsoft.Identity.Client'" />
</ItemGroup>
<Copy DestinationFolder="$(OutputPath)\WindowsAuthenticator" SourceFiles="@(WindowsAuthenticatorFiles)" />

<ItemGroup Condition="'@(MsalPackageDefinitions)' != ''">
<MSALItemsToCopy Include="%(MsalPackageDefinitions.ResolvedPath)\lib\netcoreapp2.1\*.dll">
<Destination>$(OutputPath)\MSAL\netcoreapp2.1</Destination>
</MSALItemsToCopy>

<MSALItemsToCopy Include="%(MsalPackageDefinitions.ResolvedPath)\lib\net45\*.dll">
<Destination>$(OutputPath)\MSAL\net45</Destination>
</MSALItemsToCopy>
</ItemGroup>

<Copy Condition="'@(FoundMSALReferences)' != ''" DestinationFiles="@(MSALItemsToCopy -> '%(Destination)\%(Filename)%(Extension)')" SourceFiles="@(MSALItemsToCopy)" />
</Target>

</Project>
26 changes: 14 additions & 12 deletions build/Microsoft.PowerBI.Packaging.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ Licensed under the MIT License.
<NoPackageAnalysis>true</NoPackageAnalysis>
<IncludeBuildOutput>true</IncludeBuildOutput>
<IncludeContentInPack>false</IncludeContentInPack>
<PackageOutputPath>$(RepoRoot)\PkgOut</PackageOutputPath>
<PackageOutputPath>$(RepoRoot)PkgOut</PackageOutputPath>
</PropertyGroup>

<!--
<ItemGroup Condition="'$(IsPackable)' == 'true'">
<PackageReference Include="platyPS" Version="0.9.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="platyPS" PrivateAssets="all" />
</ItemGroup>
-->

Expand All @@ -35,7 +33,11 @@ Licensed under the MIT License.
<Target Name="AddMoreProjectFiles" AfterTargets="_GetPackageFiles" Condition="'$(IsPackable)' == 'true'">

<ItemGroup>
<FilteredResolveAssemblyReferenceResolvedFiles Include="@(_ResolveAssemblyReferenceResolvedFiles)" Condition="%(_ResolveAssemblyReferenceResolvedFiles.Filename) != 'netstandard' AND %(_ResolveAssemblyReferenceResolvedFiles.Filename) != 'mscorlib' AND %(_ResolveAssemblyReferenceResolvedFiles.Filename) != 'Microsoft.CSharp'" />
<FilteredResolveAssemblyReferenceResolvedFiles Include="@(_ResolveAssemblyReferenceResolvedFiles)" Condition="%(_ResolveAssemblyReferenceResolvedFiles.Filename) != 'netstandard'
AND %(_ResolveAssemblyReferenceResolvedFiles.Filename) != 'mscorlib'
AND %(_ResolveAssemblyReferenceResolvedFiles.Filename) != 'Microsoft.CSharp'
AND %(_ResolveAssemblyReferenceResolvedFiles.Filename) != 'Microsoft.Identity.Client'
AND %(_ResolveAssemblyReferenceResolvedFiles.Filename) != 'Microsoft.Identity.Client.Extensions.Msal'" />
</ItemGroup>

<RemoveDuplicates Inputs="@(FilteredResolveAssemblyReferenceResolvedFiles)">
Expand All @@ -45,16 +47,10 @@ Licensed under the MIT License.
<Message Text="Locating netstandard assembly" Importance="high" />
<Exec ConsoleToMSBuild="true" Command="$(PowerShellExe) $(PowerShellCommonArgs) -Command &quot;&amp; { &amp;&apos;$(ScriptsRoot)GetNetstandardAssembly.ps1&apos; } &quot;">
<Output TaskParameter="ConsoleOutput" PropertyName="NetStandardDllPath" />
</Exec>
</Exec>

<ItemGroup>

<_PackageFiles Include="$(OutputPath)\WindowsAuthenticator\**\*.*" Condition="Exists('$(OutputPath)\WindowsAuthenticator')">
<BuildAction>Content</BuildAction>
<Pack>true</Pack>
<PackagePath>lib\$(TargetFramework)\WindowsAuthenticator</PackagePath>
</_PackageFiles>

<_PackageFiles Include="$(OutputPath)\settings.json" Condition="Exists('$(OutputPath)\settings.json') AND '$(NoDependentAssemblies)' != 'true'">
<BuildAction>Content</BuildAction>
<Pack>true</Pack>
Expand All @@ -73,6 +69,12 @@ Licensed under the MIT License.
<PackagePath>lib\$(TargetFramework)</PackagePath>
</_PackageFiles>

<_PackageFiles Include="$(OutputPath)\MSAL\**\*.*" Condition="Exists('$(OutputPath)\MSAL')">
<BuildAction>Content</BuildAction>
<Pack>true</Pack>
<PackagePath>lib\$(TargetFramework)\MSAL\%(RecursiveDir)</PackagePath>
</_PackageFiles>

<_PackageFiles Include="$(OutputPath)\$(LangName)\**\*.*" Condition="'$(NoHelpGen)' != 'true'">
<BuildAction>Content</BuildAction>
<Pack>true</Pack>
Expand Down
24 changes: 24 additions & 0 deletions dirs.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.Build.Traversal">

<PropertyGroup>
<SlnGenFolders>true</SlnGenFolders>
</PropertyGroup>

<ItemGroup>
<!-- Build all projects recursively under the "src" folder -->
<ProjectReference Include="src\**\*.*proj" />
</ItemGroup>

<ItemGroup>
<!-- Only pulled in by slngen -->
<SlnGenSolutionItem Include="build\**\*.targets" />
<SlnGenSolutionItem Include="scripts\**\*.*" />
<SlnGenSolutionItem Include="NuGet.config" />
<SlnGenSolutionItem Include="ReleaseNotes.md" />
<SlnGenSolutionItem Include=".editorconfig" />
<SlnGenSolutionItem Include="global.json" />
<SlnGenSolutionItem Include="Directory.Build.props" />
<SlnGenSolutionItem Include="Directory.Build.targets" />
<SlnGenSolutionItem Include="Packages.props" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"sdk": {
"version": "5.0.101"
},
"msbuild-sdks": {
"Microsoft.Build.Traversal": "3.0.2",
"Microsoft.Build.CentralPackageVersions": "2.0.79",
"Microsoft.Build.NoTargets": "2.0.1",
"Microsoft.Build.Artifacts": "2.0.35"
}
}
16 changes: 16 additions & 0 deletions init.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$scriptsDir = (Get-Item "$PSScriptRoot\scripts").FullName

if($env:Path -split ';' -inotcontains $scriptsDir) {
Write-Verbose "Adding '$scriptsDir' to Path environment variable..."
$env:Path = $env:Path.TrimEnd(';')
$env:Path += ";$scriptsDir"
}

$scripts = Get-ChildItem -Path $scriptsDir -Filter *.ps1
foreach ($script in $scripts) {
$scriptName = $script.BaseName
Set-Alias -Name $scriptName -Value $script.FullName -Scope Global -Option AllScope -ErrorAction SilentlyContinue
}

Write-Host "Any script (*.ps1) in $scriptsDir can be called with just name of script, example 'build'" -ForegroundColor Gray
Write-Host "Welcome to powerbi-powershell repository!`n" -ForegroundColor Green
42 changes: 11 additions & 31 deletions scripts/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
[CmdletBinding()]
param
(
# Path to solution file. Defaults to <script dir>\src\PowerBIPowerShell.sln.
# Path to solution file. Defaults to <script dir>\..\dirs.proj.
[ValidateNotNullOrEmpty()]
[string] $Solution = "$PSScriptRoot\..\src\PowerBIPowerShell.sln",
[string] $Solution = "$PSScriptRoot\..\dirs.proj",

# MSBuild targets to execute. Default is the Build target unless -NoBuild is specified.
[ValidateNotNull()]
Expand All @@ -45,9 +45,12 @@ param
# Indicates to execute the Pack target (generate NuGet packages).
[switch] $Pack,

# Indicates to execute the Clean target.
# Indicates to execute the Clean target. -Restore is added if you specify this.
[switch] $Clean,

# Indicates to nuget restore.
[switch] $Restore,

# Indicates to not add the Build target which is normally defaulted.
[switch] $NoBuild,

Expand All @@ -58,34 +61,7 @@ param
[switch] $NoParallel
)

function Get-VSBuildFolder
{
[OutputType([string])]
param
(
[switch] $Prerelease
)

# https://github.com/Microsoft/vswhere
$vsWhereExe = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if(!(Test-Path -Path $vsWhereExe)) {
throw "Unable to find vswhere, confirm Visual Studio is installed: $vsWhereExe"
}

$vsWhereArgs = @('-latest', '-requires', 'Microsoft.Component.MSBuild', '-find', 'MSBuild\**\Bin\MSBuild.exe')
if($Prerelease) {
$vsWhereArgs += '-prerelease'
}

# https://github.com/microsoft/vswhere/wiki/Find-MSBuild#powershell
$msbuildPath = & $vsWhereExe $vsWhereArgs | select-object -first 1
if(!(Test-Path -Path $msbuildPath)) {
throw "Unable to find MSBuild: $msbuildPath"
}

return $msbuildPath
}

Import-Module $PSScriptRoot\FindVS.psm1
$msbuildPath = Get-VSBuildFolder -Prerelease:$VSPreview

if(!$NoBuild) {
Expand Down Expand Up @@ -121,6 +97,10 @@ if($MSBuildProperties.Count -gt 0) {
$msBuildArgs += ('/p:' + ($properties -join ';'))
}

if ($Restore -or $Clean) {
$msBuildArgs += '/restore'
}

if($AppVeyorLogger) {
# https://www.appveyor.com/docs/build-phase/
$msBuildArgs += '/logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"'
Expand Down
27 changes: 27 additions & 0 deletions scripts/FindVS.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function Get-VSBuildFolder
{
[OutputType([string])]
param
(
[switch] $Prerelease
)

# https://github.com/Microsoft/vswhere
$vsWhereExe = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if(!(Test-Path -Path $vsWhereExe)) {
throw "Unable to find vswhere, confirm Visual Studio is installed: $vsWhereExe"
}

$vsWhereArgs = @('-latest', '-requires', 'Microsoft.Component.MSBuild', '-find', 'MSBuild\**\Bin\MSBuild.exe')
if($Prerelease) {
$vsWhereArgs += '-prerelease'
}

# https://github.com/microsoft/vswhere/wiki/Find-MSBuild#powershell
$msbuildPath = & $vsWhereExe $vsWhereArgs | select-object -first 1
if(!(Test-Path -Path $msbuildPath)) {
throw "Unable to find MSBuild: $msbuildPath"
}

return $msbuildPath
}
10 changes: 10 additions & 0 deletions scripts/GenerateHelp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ if($GenerateMarkdown) {

Write-Output "Finished generating Markdown files"
Remove-Module -Name $moduleName -Force -ErrorAction SilentlyContinue

Write-Output "Updating http to https in Markdown files"
$mdFiles = Get-ChildItem -Path $helpFolder -Filter *.md
$mdFiles | ForEach-Object {
$mdContent = Get-Content -Path $_.FullName -Raw
$mdContent = $mdContent -replace 'http://', 'https://'
$mdContent | Out-File -FilePath $_.FullName -Encoding utf8 -Force
}

Write-Output "Finished updating http:// to https:// in Markdown files"
}

if($GenerateExternalHelp) {
Expand Down
Loading

0 comments on commit 4675e53

Please sign in to comment.