devblackops / building-powershell-modules-feedback

Feedback on the PowerShell Module Development book
6 stars 1 forks source link

Code Error: #25

Closed Dev-Larks closed 4 years ago

Dev-Larks commented 4 years ago

Description

When using the build.ps1 script from section 9.4.2.1 Creating an output directory

I'm getting errors saying that the .ps1 files in the $sourceFiles variable cannot be found as the paths it is using are incorrect.

Chapter/section/subsection

Current behavior

PS C:\DEV\AcmeEmployee> .\build.ps1

Get-Content : Cannot find path 'C:\DEV\AcmeEmployee\Initialise.ps1' because it does not exist. At C:\DEV\AcmeEmployee\build.ps1:25 char:5

Expected behavior

These .ps1 files are supposed to be found in the next directory down, but the paths are incorrect. The contents of each .ps1 file is then taken and placed in the .psm1 file in the Output directory

Possible solution

Screenshots

Build_001 - values in $sourceFiles variable Build_002 - error messages when content of individual .ps1 files are attempted to be added to Output .psm1 file Build_003 - current module structure Build_004 - Output folder .psm1 file content Build_005 - Actual content of build.ps1 file Build_001 Build_002 Build_003 Build_004 Build_005

clee1107 commented 4 years ago

Seeing same issue.

Can clear errors by adding sub module name

$sourceFiles = Get-ChildItem -Path ./AcmeEmployee/AcmeEmployee -Filter '*.ps1' -Recurse

But then no .psm1 file is created in Output

Was able to get code to copy by making following adjustment:

$sourceFiles | ForEach-Object { "# source: $($_.Name)" Get-Content "$($_.Directory)\$($_.Name)" '' } | Add-Content -Path $rootModule -Encoding utf8

devblackops commented 4 years ago

Doh! Thanks for finding this! Fix will be incoming.

devblackops commented 4 years ago

Thanks for reporting this. Are you using Windows PowerShell? This looks like broken behavior in Windows PowerShell that has since been fixed in PowerShell Core.

The problem is with Get-Content $_. That fails in Windows PowerShell but not PowerShell Core.

Try changing it to:

Get-Content -Path $_.FullName

OR

$_ | Get-Content

Sorry for the bug! The text has been updated and will be in the next update.

Dev-Larks commented 4 years ago

Hi Brandon

I was using PowerShell 5.1 as I was doing this on my work laptop.

I’ll check your solution and confirm early next week if the issue is no longer occurring.

Cheers Craig

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: Brandon Olinmailto:notifications@github.com Sent: Friday, 3 July 2020 9:23 AM To: devblackops/building-powershell-modules-feedbackmailto:building-powershell-modules-feedback@noreply.github.com Cc: Dev-Larksmailto:dev_larks@outlook.com; Authormailto:author@noreply.github.com Subject: Re: [devblackops/building-powershell-modules-feedback] Code Error: (#25)

Thanks for reporting this. Are you using Windows PowerShell? This looks like broken behavior in Windows PowerShell that has since been fixed in PowerShell Core.

The problem is with Get-Content $_. That fails in Windows PowerShell but not PowerShell Core.

Try changing it to:

Get-Content -Path $_.FullName

OR

$_ | Get-Content

Sorry for the bug! The text has been updated and will be in the next update.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/devblackops/building-powershell-modules-feedback/issues/25#issuecomment-653258230, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKT7CTI7AHDCEO3PSJ7X4FDRZUJGTANCNFSM4ONB6QMA.

Dev-Larks commented 4 years ago

Hi Brandon

Had a chance to test today, confirming the expected behaviour when running the .\build.ps1 file is now occurring using either of the two solutions you provided.

Regards

Craig

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: Craig Larkinmailto:Dev_Larks@outlook.com Sent: Friday, 3 July 2020 4:30 PM To: devblackops/building-powershell-modules-feedbackmailto:reply@reply.github.com Subject: RE: [devblackops/building-powershell-modules-feedback] Code Error: (#25)

Hi Brandon

I was using PowerShell 5.1 as I was doing this on my work laptop.

I’ll check your solution and confirm early next week if the issue is no longer occurring.

Cheers Craig

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: Brandon Olinmailto:notifications@github.com Sent: Friday, 3 July 2020 9:23 AM To: devblackops/building-powershell-modules-feedbackmailto:building-powershell-modules-feedback@noreply.github.com Cc: Dev-Larksmailto:dev_larks@outlook.com; Authormailto:author@noreply.github.com Subject: Re: [devblackops/building-powershell-modules-feedback] Code Error: (#25)

Thanks for reporting this. Are you using Windows PowerShell? This looks like broken behavior in Windows PowerShell that has since been fixed in PowerShell Core.

The problem is with Get-Content $_. That fails in Windows PowerShell but not PowerShell Core.

Try changing it to:

Get-Content -Path $_.FullName

OR

$_ | Get-Content

Sorry for the bug! The text has been updated and will be in the next update.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/devblackops/building-powershell-modules-feedback/issues/25#issuecomment-653258230, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKT7CTI7AHDCEO3PSJ7X4FDRZUJGTANCNFSM4ONB6QMA.

devblackops commented 4 years ago

Thanks for checking back @Dev-Larks 👍