Comments (10)
I suspected as much. What do you get with this command:
$Host.UI.RawUI | gm
from invoke-build.
Hello,
PS /home/ubuntu> $Host.UI.RawUI | gm
TypeName: System.Management.Automation.Internal.Host.InternalHostRawUserInterface
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
FlushInputBuffer Method void FlushInputBuffer()
GetBufferContents Method System.Management.Automation.Host.BufferCell[,] GetBufferContents(System.Management.Automation.Host.Rectangle r)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
LengthInBufferCells Method int LengthInBufferCells(string str), int LengthInBufferCells(string str, int offset), int LengthInBufferCells(char character)
NewBufferCellArray Method System.Management.Automation.Host.BufferCell[,] NewBufferCellArray(string[] contents, System.ConsoleColor foregroundColor, System.ConsoleColor backgroundColor), Sy... ReadKey Method System.Management.Automation.Host.KeyInfo ReadKey(System.Management.Automation.Host.ReadKeyOptions options), System.Management.Automation.Host.KeyInfo ReadKey()
ScrollBufferContents Method void ScrollBufferContents(System.Management.Automation.Host.Rectangle source, System.Management.Automation.Host.Coordinates destination, System.Management.Automati... SetBufferContents Method void SetBufferContents(System.Management.Automation.Host.Coordinates origin, System.Management.Automation.Host.BufferCell[,] contents), void SetBufferContents(Syst... ToString Method string ToString()
BackgroundColor Property System.ConsoleColor BackgroundColor {get;set;}
BufferSize Property System.Management.Automation.Host.Size BufferSize {get;set;}
CursorPosition Property System.Management.Automation.Host.Coordinates CursorPosition {get;set;}
CursorSize Property int CursorSize {get;set;}
ForegroundColor Property System.ConsoleColor ForegroundColor {get;set;}
KeyAvailable Property bool KeyAvailable {get;}
MaxPhysicalWindowSize Property System.Management.Automation.Host.Size MaxPhysicalWindowSize {get;}
MaxWindowSize Property System.Management.Automation.Host.Size MaxWindowSize {get;}
WindowPosition Property System.Management.Automation.Host.Coordinates WindowPosition {get;set;}
WindowSize Property System.Management.Automation.Host.Size WindowSize {get;set;}
WindowTitle Property string WindowTitle {get;set;}
PS /home/ubuntu> $Host.UI.RawUI
ForegroundColor : -1
BackgroundColor : -1
CursorPosition : 0,48
WindowPosition : 0,0
CursorSize : 100
BufferSize : 200,49
WindowSize : 200,49
MaxWindowSize : 200,49
MaxPhysicalWindowSize : 200,49
KeyAvailable : False
WindowTitle :
from invoke-build.
I reduced some of the errors but got to an impasse with the PSHost requirement.
Code changes:
Add-Type -referencedAssemblies 'System.Console' -TypeDefinition @'
using System;
using System.Collections.Generic;
public class IB {
[ThreadStatic] static ConsoleColor _c;
[ThreadStatic] static PSHostRawUserInterface _u;
static public void Init(PSHost h) {if (h.UI != null) _u = h.UI.RawUI;}
static public void RC() {if (_u != null) {try {_u.ForegroundColor = _c;} catch {}}}
static public void SC(ConsoleColor c) {if (_u != null) {try {_c = _u.ForegroundColor; _u.ForegroundColor = c;} catch {_u = null;}}}
static public object List() {return new List<object>();}
}
'@
[IB]::Init($Host)
Resulting error on a test build with a few small tasks:
PS /vagrant> ./Invoke-Build.ps1
Add-Type : (7) : The type or namespace name 'PSHost' could not be found (are you missing a using directive or an assembly reference?)
(6) : [ThreadStatic] static PSHostRawUserInterface _u;
(7) : >>> static public void Init(PSHost h) {if (h.UI != null) _u = h.UI.RawUI;}
(8) : static public void RC() {if (_u != null) {try {_u.ForegroundColor = _c;} catch {}}}
At /vagrant/Invoke-Build.ps1:203 char:1
+ Add-Type -referencedAssemblies 'System.Console' -TypeDefinition @'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : (6) : The type or namespace name 'PSHostRawUserInterface' could not be found (are you missing a using directive or an assembly reference?)
(5) : [ThreadStatic] static ConsoleColor _c;
(6) : >>> [ThreadStatic] static PSHostRawUserInterface _u;
(7) : static public void Init(PSHost h) {if (h.UI != null) _u = h.UI.RawUI;}
At /vagrant/Invoke-Build.ps1:203 char:1
+ Add-Type -referencedAssemblies 'System.Console' -TypeDefinition @'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Cannot add type. Compilation errors occurred.
At /vagrant/Invoke-Build.ps1:203 char:1
+ Add-Type -referencedAssemblies 'System.Console' -TypeDefinition @'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
+ FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
Unable to find type [IB].
At /vagrant/Invoke-Build.ps1:216 char:1
+ [IB]::Init($Host)
+ ~~~~
+ CategoryInfo : InvalidOperation: (IB:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
/vagrant/Invoke-Build.ps1 : Unable to find type [IB].
At line:1 char:1
+ ./Invoke-Build.ps1
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (IB:TypeName) [Invoke-Build.ps1], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound,Invoke-Build.ps1
from invoke-build.
We have to find the assembly of $Host.UI.RawUI
and also add it to the
referenced assemblies. And so on with other troublesome types.
Please take a look at
$Host.UI.RawUI.GetType().Assembly | Format-List *
and/or
function Get-AssemblyPath($obj) {$obj.GetType().Assembly.Location}
Get-AssemblyPath $Host
Get-AssemblyPath $Host.UI
Get-AssemblyPath $Host.UI.RawUI
It looks like using Add-Type
is fragile, at least at this point. It makes
sense to think of removing it from Invoke-Build
. If you cannot resolve the
errors by adding missing referenced assemblies then try the older
Invoke-Build.ps1
(v2.14.2) which does not use Add-Type
yet:
https://github.com/nightroman/Invoke-Build/blob/v2.14.2/Invoke-Build.ps1
It would be very useful to know what the next problem is.
It might be something related to used wrong slashes in paths.
from invoke-build.
On the other hand, Add-Type
has many opened issues and hopefully many of them will be resolved. For example, this one also mentions ConsoleColor
: PowerShell/PowerShell#1616
I believe Add-Type
should add more assemblies to default referenced.
At least types used in public PowerShell API should be covered.
So it makes sense to concentrate on potential issues other than Add-Type
and try the older Invoke-Build v2.14.2.
from invoke-build.
@zloeber, in a few hours I will commit fixes for known and potential issues. I hope you can help me with testing it.
from invoke-build.
I'll try to test today. I've dug into the .Net core libraries and am fairly certain that PSHost is not part of them. I'm not as fluent with custom powershell hosts as I probably should be at this point but is there any way to code our way around this requirement?
Add-Type has many interesting issues and is powerful but painful at the same time :)
from invoke-build.
Please try the current script and let me know the result. I removed Add-Type and fixed a few slashes.
from invoke-build.
And a successful build!
PS /vagrant> ./Invoke-Build.ps1
Build . /vagrant/.build.ps1
Task /.
Are we configured here?...Yup!
Task /.
Are we configured here?...Yup!
Done /. 00:00:00.0427840
Build succeeded. 1 tasks, 0 errors, 0 warnings 00:00:00.1943410
Congrats, this is probably the first useful posh project to get cross platform :).
from invoke-build.
Thank you! This would take much longer without your report and help. I think the story is not over yet and there will be issues. But the first working build is a great step forward.
from invoke-build.
Related Issues (20)
- Amend output on task errors.
- Reusing or sharing tasks HOT 5
- ib.cmd ? ignores a specified file
- vscode outline view: no symbols found in document HOT 2
- Different module and package versions HOT 2
- Parallel execution based on dependency tree HOT 2
- invoke-build discovery fails in powershell container HOT 3
- Please consider adding -Computername and -Session parameter to Task HOT 8
- GitHub action output is not colored
- Color and formatting text in Azure DevOps Pipelines HOT 8
- Use-BuildEnv should make parameters mandatory
- Invoke-BuildExec spitting out service principal secret as current directory HOT 6
- Exec doesn't work well with forward slash arguments HOT 7
- Use `[System.Management.Automation.Cmdlet]::CommonParameters` to get the names of all common parameters HOT 3
- Task condition does not work HOT 8
- Build-Parallel writes only to Output stream HOT 7
- property 'File' cannot be found on this object HOT 17
- Do not wrap internal errors in Resolve-MSBuild
- Fix cryptic errors on unknown parameters
- Invoke-BuildExec should pass the original stderr error to the thrown terminating error HOT 38
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from invoke-build.