mirror of
				https://github.com/esiur/esiur-dotnet.git
				synced 2025-10-30 23:51:34 +00:00 
			
		
		
		
	Added Records
This commit is contained in:
		
							
								
								
									
										115
									
								
								Esiur/Tools/Esiur.psm1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								Esiur/Tools/Esiur.psm1
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,115 @@ | ||||
| function Get-Template($url, $dir, $username, $password) | ||||
| { | ||||
|  | ||||
|    $lib = Resolve-Path -Path "$($PSScriptRoot)\..\lib\netstandard2.0\Esiur.dll"             | ||||
|    #write-host "Lib is at $($lib)" | ||||
|  | ||||
|    $assembly =  [Reflection.Assembly]::LoadFile($lib) | ||||
|    $tempPath =  [Esiur.Proxy.TemplateGenerator]::GetTemplate($url, $dir, $username,$password);   | ||||
|    | ||||
|   $startupProject = GetStartupProject | ||||
|    | ||||
| 	$activeConfiguration = $startupProject.ConfigurationManager.ActiveConfiguration | ||||
|     if ($activeConfiguration -eq $null) | ||||
|     { | ||||
|         throw "Unable to read project configuration settings of project '$($startupProject.ProjectName)' for the " + | ||||
|             'active solution configuration. Try closing Package Manager Console and restarting Visual Studio. If the ' + | ||||
|             'problem persists, use Help > Send Feedback > Report a Problem.' | ||||
|     } | ||||
| 	 | ||||
| 	 | ||||
|     $startupProject.ProjectItems.AddFromDirectory($tempPath) | Out-Null	 | ||||
| } | ||||
|  | ||||
| function GetStartupProject($name, $fallbackProject) | ||||
| { | ||||
|     if ($name) | ||||
|     { | ||||
|         return Get-Project $name | ||||
|     } | ||||
|  | ||||
|     $startupProjectPaths = $DTE.Solution.SolutionBuild.StartupProjects | ||||
|     if ($startupProjectPaths) | ||||
|     { | ||||
|         if ($startupProjectPaths.Length -eq 1) | ||||
|         { | ||||
|             $startupProjectPath = $startupProjectPaths[0] | ||||
|             if (![IO.Path]::IsPathRooted($startupProjectPath)) | ||||
|             { | ||||
|                 $solutionPath = Split-Path (GetProperty $DTE.Solution.Properties 'Path') | ||||
|                 $startupProjectPath = [IO.Path]::GetFullPath((Join-Path $solutionPath $startupProjectPath)) | ||||
|             } | ||||
|  | ||||
|             $startupProject = GetSolutionProjects | ?{ | ||||
|                 try | ||||
|                 { | ||||
|                     $fullName = $_.FullName | ||||
|                 } | ||||
|                 catch [NotImplementedException] | ||||
|                 { | ||||
|                     return $false | ||||
|                 } | ||||
|  | ||||
|                 if ($fullName -and $fullName.EndsWith('\')) | ||||
|                 { | ||||
|                     $fullName = $fullName.Substring(0, $fullName.Length - 1) | ||||
|                 } | ||||
|  | ||||
|                 return $fullName -eq $startupProjectPath | ||||
|             } | ||||
|             if ($startupProject) | ||||
|             { | ||||
|                 return $startupProject | ||||
|             } | ||||
|  | ||||
|             Write-Warning "Unable to resolve startup project '$startupProjectPath'." | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             Write-Warning 'Multiple startup projects set.' | ||||
|         } | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         Write-Warning 'No startup project set.' | ||||
|     } | ||||
|  | ||||
|     Write-Warning "Using project '$($fallbackProject.ProjectName)' as the startup project." | ||||
|  | ||||
|     return $fallbackProject | ||||
| } | ||||
|  | ||||
| function GetProperty($properties, $propertyName) | ||||
| { | ||||
|     try | ||||
|     { | ||||
|         return $properties.Item($propertyName).Value | ||||
|     } | ||||
|     catch | ||||
|     { | ||||
|         return $null | ||||
|     } | ||||
| } | ||||
|  | ||||
| function GetSolutionProjects() | ||||
| { | ||||
|     $projects = New-Object 'System.Collections.Stack' | ||||
|  | ||||
|     $DTE.Solution.Projects | %{ | ||||
|         $projects.Push($_) | ||||
|     } | ||||
|  | ||||
|     while ($projects.Count) | ||||
|     { | ||||
|         $project = $projects.Pop(); | ||||
|  | ||||
|         <# yield return #> $project | ||||
|  | ||||
|         if ($project.ProjectItems) | ||||
|         { | ||||
|             $project.ProjectItems | ?{ $_.SubProject } | %{ | ||||
|                 $projects.Push($_.SubProject) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user