Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [CmdletBinding()]
- param(
- [Parameter(Mandatory = $true)]
- [string]
- $SolutionDir,
- [Parameter(Mandatory = $true)]
- [string]
- $Configuration
- )
- . "$PSScriptRoot\models.ps1"
- $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
- $loadOrder = @(
- 'System.Collections.Immutable.dll',
- 'System.Threading.Tasks.Dataflow.dll',
- 'Microsoft.VisualStudio.Setup.Configuration.Interop.dll',
- 'Microsoft.Build.Framework.dll',
- 'Microsoft.Build.dll',
- 'Microsoft.Build.Utilities.Core.dll'
- )
- $loadOrder | ForEach-Object { Add-Type -Path "$PSScriptRoot\bin\$_" }
- $solutionFilePath = Join-Path $SolutionDir "HRNet.sln"
- if ( -not ( Test-Path $solutionFilePath ) ) {
- throw "Solution file 'HRNet.sln' cannot be found in path '$SolutionDir'"
- }
- $PackageRegExpr = New-Object System.Text.RegularExpressions.Regex("(?:[\.\.\\]+)(?:\\packages\\)(.+?)\.((?:\.?[0-9]+)+)")
- $VersionRegExpr = New-Object System.Text.RegularExpressions.Regex("([0-9]+)(\.[0-9]+){1,3}")
- $DllRegExpr = New-Object System.Text.RegularExpressions.Regex("[^\\]+.dll")
- $TestRegExpr = New-Object System.Text.RegularExpressions.Regex("Test")
- $MsBuildSolution = [Microsoft.Build.Construction.SolutionFile]::Parse( $solutionFilePath )
- $realProjects = $MsBuildSolution.ProjectsInOrder | Where-Object {
- $_.AbsolutePath.EndsWith(".csproj") -or $_.AbsolutePath.EndsWith(".fsproj")
- }
- $ProjectInfos = @{ }
- $ProjectLookupByName = @{ }
- $TestProjects = @( )
- foreach ( $proj in $realProjects ) {
- $MsBuildProject = New-Object Microsoft.Build.Evaluation.Project( $proj.AbsolutePath )
- $ProjectId = [System.Guid]::Parse( $proj.ProjectGuid )
- $ProjectName = $proj.ProjectName
- $AssemblyName = $MsBuildProject.GetPropertyValue( 'AssemblyName' )
- $OutputDirectory = $MsBuildProject.GetPropertyValue( 'TargetDir' ).Replace( 'Debug', $Configuration )
- $TargetPath = $MsBuildProject.GetPropertyValue( 'TargetPath' )
- $FileName = $MsBuildProject.GetPropertyValue( 'TargetFileName' )
- if ( $TestRegExpr.IsMatch( $ProjectName ) ) {
- $TestProjects += $AssemblyName
- }
- $ProjectLookupByName.Add( $AssemblyName, $ProjectId )
- $projectDependencies = New-Object System.Collections.Generic.HashSet[System.Guid]
- $referencedAssemblies = New-Object System.Collections.Generic.HashSet[PackageInfo]
- foreach ( $projItem in $MsBuildProject.Items ) {
- if ( $projItem.ItemType -eq 'Reference' ) {
- $projItem.Metadata | Where-Object { $_.Name -eq 'HintPath' } | ForEach-Object {
- $relativeDir = $_.EvaluatedValue
- $absolutePath = [System.IO.Path]::GetFullPath( [System.IO.Path]::Combine( $MsBuildProject.DirectoryPath, $relativeDir ) )
- $match = $PackageRegExpr.Match( $_.EvaluatedValue )
- if ( $match.Success ) {
- $name = $DllRegExpr.Match( $_.EvaluatedValue ).Value
- $versionMatch = $VersionRegExpr.Match( $match.Groups[2].Value )
- $version = [System.Version]::Parse( $versionMatch.Value )
- }
- else {
- $name = ''
- $version = $null
- }
- $referencedAssemblies.Add( [PackageInfo]::new( $name, $absolutePath, $version ) ) | Out-Null
- }
- }
- elseif ( $projItem.ItemType -eq 'ProjectReference' ) {
- $projItem.Metadata | Where-Object { $_.Name -eq 'Project' } | ForEach-Object {
- $projectDependencies.Add( [System.Guid]::Parse( $_.EvaluatedValue ) ) | Out-Null
- }
- }
- }
- $projectInfos.Add(
- $ProjectId,
- [ProjectInfo]::new( $ProjectId, $ProjectName, $AssemblyName, $OutputDirectory, $TargetPath, $FileName, $referencedAssemblies, $projectDependencies )
- ) | Out-Null
- }
- $DependenciesByProject = @{ }
- foreach ( $projGuid in $ProjectInfos.Keys ) {
- $dependenciesToVisit = New-Object System.Collections.Generic.Stack[System.Guid]
- $seenProjects = New-Object System.Collections.Generic.HashSet[System.Guid]
- $assemblies = New-Object System.Collections.Generic.HashSet[PackageInfo]
- $allProjectDependencies = New-Object System.Collections.Generic.HashSet[System.Guid]
- $dependenciesToVisit.Push( $projGuid )
- $seenProjects.Add( $projGuid ) | Out-Null
- while ( $dependenciesToVisit.Count -ne 0 ) {
- $currentProjectId = $dependenciesToVisit.Pop()
- $project = $ProjectInfos[ $currentProjectId ]
- $allProjectDependencies.Add( $currentProjectId ) | Out-Null
- $assemblies.UnionWith( $project.ReferencedAssemblies )
- foreach ( $dep in $project.ProjectDependencies ) {
- if ( -not $seenProjects.Contains( $dep ) ) {
- $dependenciesToVisit.Push( $dep )
- $seenProjects.Add( $dep ) | Out-Null
- }
- }
- }
- $lookup = @{ }
- $notPackages = New-Object System.Collections.Generic.HashSet[PackageInfo]
- foreach ($reference in $assemblies) {
- if ($reference.Name -eq '') {
- $notPackages.Add( $reference ) | Out-Null
- continue
- }
- if ( $lookup.ContainsKey( $reference.Name ) ) {
- $seenVersion = $lookup[ $reference.Name ].PackageVersion
- $currentVersion = $reference.PackageVersion
- if ( $currentVersion.CompareTo( $seenVersion ) -eq 1 ) {
- $lookup[ $reference.Name ] = $reference
- }
- }
- else {
- $lookup.Add( $reference.Name, $reference ) | Out-Null
- }
- }
- $assemblies = New-Object System.Collections.Generic.HashSet[PackageInfo]
- $lookup.Keys | ForEach-Object { $assemblies.Add( $lookup[ $_ ] ) | Out-Null }
- $assemblies.UnionWith( $notPackages )
- $allProjectDependencies.Remove( $projGuid ) | Out-Null
- $DependenciesByProject.Add(
- $projGuid,
- [ProjectDependencies]::new( $assemblies, $allProjectDependencies )
- ) | Out-Null
- }
- $ExecutableProjects = @(
- 'erecruit.Web',
- 'erecruit.Mvc',
- 'erecruit.Mvc.Search',
- 'erecruit.WebApi',
- 'erecruit.Mobile',
- 'RESTServices2',
- 'SearchService',
- 'erecruit.TaskService2',
- 'erecruitTaskService',
- 'erecruit.ServiceBus.ListenerService',
- 'erecruit.ChangeBrokerService',
- 'erecruit.Indexing.Rehydrator',
- 'erecruit.SqlGenerator',
- 'csman',
- 'erecruit.Localization.ImportExport',
- 'OnboardingRefactoringMigration',
- 'PopulateIndex',
- 'ResumeImport',
- 'SearchServiceTest',
- 'sbman',
- 'vcs',
- 'IndexingDefinitions',
- 'erecruit.IndexingManager',
- 'erecruit.IntegrationManager',
- 'ClientSecretHasher',
- 'EncryptPhoneSystemPassword',
- 'SsnHasher',
- 'erecruit.Stamp',
- 'erecruitDispatchService'
- )
- foreach ( $executableProjectName in ( $ExecutableProjects + $TestProjects ) ) {
- $projId = $ProjectLookupByName[ $executableProjectName ]
- [ProjectInfo] $projectInfo = $ProjectInfos[ $projId ]
- [ProjectDependencies] $projDependencies = $DependenciesByProject[ $projId ]
- foreach ( $assembly in $projDependencies.ReferencedAssemblies ) {
- $fileName = [System.IO.Path]::GetFileName( $assembly.AbsolutePath )
- New-Item -ItemType HardLink `
- -Path ( Join-Path $projectInfo.OutputDirectory $fileName ) `
- -Target $assembly.AbsolutePath `
- -Force | Out-Null
- }
- foreach ( $projectId in $projDependencies.Projects ) {
- [ProjectInfo] $info = $ProjectInfos[ $projectId ]
- $path = Join-Path $projectInfo.OutputDirectory $info.FileName
- New-Item -ItemType HardLink `
- -Path $path `
- -Target $info.TargetPath `
- -Force | Out-Null
- }
- }
- $stopwatch.Stop()
- Write-Host "Hard links created in $($stopwatch.Elapsed)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement