rodneyviana / ODSyncService

OneDrive service/DLL for Sync State
MIT License
93 stars 26 forks source link

PSGallery Module #44

Open variableresistor opened 1 year ago

variableresistor commented 1 year ago

Thanks for writing this module. I had a specific use-case where I needed my automation to notify a distribution list when documents were successfully uploaded to a SharePoint site. Have you considered publishing this module to the PowerShell Gallery? It'd save a lot of the setup overhead and having to explain the process. I've taken some time to write a script you can use to save you the trouble:

$Script:ErrorActionPreference = 'Stop'
$Script:PSDefaultParameterValues = @{
    "Select-Object:First" = 1
}

$DLLPath = Get-ChildItem -File -Path $PSScriptRoot -Filter "OneDriveLib.dll" -Recurse | Select-Object -ExpandProperty FullName
if (-not $DLLPath) { Write-Error "Build the DLL first" }

$ModuleFolderPath = "$env:OneDriveLib"
if (-not (Test-Path $ModuleFolderPath))
{
    New-Item -Path $ModuleFolderPath -ItemType Directory
}

$DLLPath = Copy-Item -Path $DLLPath -Destination $ModuleFolderPath -PassThru | Select-Object -ExpandProperty FullName
Unblock-File -Path $DLLPath
$DLLFileProperties = Get-ItemProperty $DLLPath
$ModuleProperties = Get-Module OneDriveLib

$Splat = @{
    Path = "$ModuleFolderPath\OneDriveLib.psd1"
    NestedModules = @()
    Guid = $ModuleProperties.Guid | Select-Object
    Author = $ModuleProperties.Author | Select-Object
    CompanyName = $ModuleProperties.CompanyName | Select-Object
    Copyright = $ModuleProperties.Copyright | Select-Object
    ModuleVersion = $ModuleProperties.Version | Select-Object
    Description = $ModuleProperties.Definition | Select-Object
    Tags = if ($ModuleProperties.Tags) { $ModuleProperties.Tags | Select-Object } else { "OneDrive" }
    CmdletsToExport = @($ModuleProperties.ExportedCmdlets.Keys)
    FunctionsToExport = @($ModuleProperties.ExportedFunctions.Keys)
    VariablesToExport = @($ModuleProperties.ExportedVariables.Keys)
    AliasesToExport = @($ModuleProperties.ExportedAliases.Keys)
    LicenseUri = $ModuleProperties.LicenseUri | Select-Object
    ProjectUri = $ModuleProperties.ProjectUri | Select-Object
    RootModule = $DLLFileProperties.Name
}
New-ModuleManifest @Splat

Split-Path $ModuleFolderPath | Where-Object { $_ -notin ($env:PSModulePath -split ",") } | ForEach-Object {
    $env:PSModulePath += ";$_"
}

Publish-Module -Name $ModuleProperties.Name -Repository PSGallery -NuGetApiKey $env:NuGetApiKey -Verbose
rodneyviana commented 6 months ago

Try this new version: https://github.com/rodneyviana/ODSyncUtil/

I would love to have you as contributor to create a nugget. Please push to the source and request a PR and I will happily save in the gallery. I was looking forward to it. Thanks.

variableresistor commented 5 months ago

Try this new version: https://github.com/rodneyviana/ODSyncUtil/

I would love to have you as contributor to create a nugget. Please push to the source and request a PR and I will happily save in the gallery. I was looking forward to it. Thanks.

What would you like the PowerShell module to be called? The DLL in this repo is called OneDriveLib, but in the other repository there's an executable called ODSyncUtil.

rodneyviana commented 5 months ago

The DLL is the beta version but will become the main version. So you call it ODSyncUtil. Create for the DLL and PowerShell version only. I really appreciate your help

variableresistor commented 5 months ago

The DLL is the beta version but will become the main version. So you call it ODSyncUtil. Create for the DLL and PowerShell version only. I really appreciate your help

https://github.com/rodneyviana/ODSyncUtil/pull/13 Like this?

rodneyviana commented 4 months ago

variableresistor,

I never published a Nuget and I may be asking something it is already in your solution:

  1. How the Nuget will know which commands are available?
  2. The new version DLL is not managed code and is does not export any PowerShell command, the cmdLet itself is the PowerShell script ODSyncUtil/Get-ODStatus.ps1

Please let me know your thoughts

variableresistor commented 4 months ago

variableresistor,

I never published a Nuget and I may be asking something it is already in your solution:

  1. How the Nuget will know which commands are available?
  2. The new version DLL is not managed code and is does not export any PowerShell command, the cmdLet itself is the PowerShell script ODSyncUtil/Get-ODStatus.ps1

Please let me know your thoughts

That's what I was sort of confused about. If you're publishing as a DLL like this script is anticipating, then the Cmdlets are being exported in the PowerShell Cmdlet project in Visual Studio. But what I can do is wrap the content of the Get-ODStatus.ps1 file into a function. That's not too difficult for me to implement. You're signing the script in New-Release.ps1, right? So is there a need for a hard-coded signature block at the bottom of this file since its being overwritten anyway?