OneGet / oneget

PackageManagement (aka OneGet) is a package manager for Windows
MIT License
2.39k stars 189 forks source link

PackageManagement DSC Resources #473

Open iSnackyCracky opened 5 years ago

iSnackyCracky commented 5 years ago

I'm not sure, if this is the correct place, but either I don't understand DSC Resources, or the PackageManagement ones aren't coming from this Module.

I'm on a freshly installed Windows 10 Pro 1903 build 18362.30) machine and I try to setup a PackageProvider and a PackageSource with InstallationPolicy of "Trusted". The DSC Configuration looks like this:

Configuration TestConfig {
    Import-DscResource -ModuleName PackageManagement
    Import-DscResource -ModuleName PsDesiredStateConfiguration

    PackageManagementSource NuGetRepo {
        Name = "NuGet"
        Ensure = "Present"
        ProviderName = "NuGet"
        SourceUri = "http://nuget.org/api/v2"
        InstallationPolicy = "Trusted"
    }

    PackageManagementSource PSGallery
    {
        Ensure = "Present"
        Name = "PSGallery"
        ProviderName = "PowerShellGet"
        SourceUri = "https://www.powershellgallery.com/api/v2/"
        InstallationPolicy = "Trusted"
    }
}

If I now deploy this and test the configuration, everything seems to be okay:

PS C:\install> Start-DscConfiguration .\TestConfig\
PS C:\install> Test-DscConfiguration
True

The NuGet PackageProvider get's added correctly, even though I couldn't find any reference in the DSC-Resource files to calling anything provider-related

PS C:\install> Get-PackageProvider
Name                     Version          DynamicOptions
----                     -------          --------------
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
NuGet                    2.8.5.208        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag...
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, ...
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent

The PSGallery PackageSource however didn't get the IsTrusted status. (It was already registered before starting the DSC Configuration):

PS C:\install> Get-PackageSource
Name                             ProviderName     IsTrusted  Location
----                             ------------     ---------  --------
PSGallery                        PowerShellGet    False      https://www.powershellgallery.com/api/v2

This seems weird after looking into the MSFT_PackageManagementSource.psm1 module. If I run the Get-TargetResource function manually, it even returns Ensure = Absent:

PS C:\install> Get-TargetResource -Name PSGallery -ProviderName PowerShellGet -SourceUri "https://www.powershellgallery.com/api/v2/"
True

Name                           Value
----                           -----
Name                           PSGallery
Ensure                         Absent
ProviderName                   PowerShellGet

Am I doing something wrong? Are those functions (from the MSFT_PackageManagementSource.psm1) even used by DSC? I am just starting experimenting with DSC and a bit confused now.

jwittner commented 5 years ago

I've run into this before and was confused until I saw this note in the docs:

Package Management sources registered in this way are registered under the System context, usable by the System account or by the DSC engine.

I believe Package Sources and PS Repositories are per user, so perhaps you could use the PsDscRunAsCredential parameter and it would register the source under the desired user, but I haven't tested that hypothesis.