PowerShellGetv2 icon indicating copy to clipboard operation
PowerShellGetv2 copied to clipboard

Publish-Module cannot be used on default $(OutputPath) for binary module

Open heaths opened this issue 5 years ago • 3 comments

I've created a lot of modules (publicly, and for internal tooling) and always find myself having to reinvent the wheel when it comes to packaging and publishing PowerShell modules because Publish-Module expects modules to be laid out as if they were installed, which really seems like getting the cart before the horse. It would be ideal if, at least when using the -Path parameter set, Publish-Module didn't just assume the module is laid out correct, or fail otherwise.

Steps to reproduce

  1. Create new project directory: mkdir test
  2. Create a new project: dotnet new classlib
  3. Add references: dotnet add package PowerShellStandard.Library
  4. Add a binary cmdlet
  5. Build: dotnet build
  6. Try to package: publish-module -path bin\Debug (other args)

Expected behavior

It packages and publishes the module.

Actual behavior

publish-module : The specified module with path '.\bin\Debug' was not published because no valid module was found with that path.

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Microsoft Windows 10.0.17763 
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

(Though this happens/has happened with every version of (Windows) PowerShell. PowerShellGet is also at 2.1.2.

heaths avatar Apr 16 '19 21:04 heaths

At present we expect there will be a .psd1 file containing the module manifest. Without that there's a bunch of data missing (what would you like the module to be called, for example?). So I feel like having a manifest in your project is going to be a requirement.

Beyond that, yes, the file layout Publish-Module requires and the default layout dotnet/msbuild creates are different, which is a nuisance. Willing to consider PRs which don't break existing publish commands, but don't expect we can work on it soon.

edyoung avatar Apr 17 '19 06:04 edyoung

Almost every module I've written uses a properly formed PSD1 file, but the problem here is that a specific directory structure is required. If -Path is used, is there any reason to think that, if the current directory structure isn't present, assuming everything local (as if msbuild produced it) would be breaking? Otherwise, I could add a switch parameter to opt into this new behavior.

heaths avatar Apr 17 '19 08:04 heaths

A module manifest would be the minimum requirement I would think (even though .psm1 can be used standalone, it's not a best practice). If there is a .psd1 in the target path, we could assume the name of the psd1 is the module name as they have to match anyways.

SteveL-MSFT avatar May 31 '19 18:05 SteveL-MSFT