Finding third party licenses with Nuget - licensing

I'm a bit of a NuGet newbie and have come from the Maven world.
Recently I've been tasked with updating the third party licence information for our projects. Working with the Maven projects I've been able to use the license:download-licenses plugin to get the licence information.
What I'm wondering is if there is a way to get this information using Nuget? Preferably by using the command line interface so I can automate it at a CI build level. To remove it from the large manual pre build step.
EDIT:
Since I wasn't able to find any utilities to do this I put together the LegSec command line utility.

As far as I am aware there is nothing currently available to get the license information directly from the command line as part of a CI build. You would need to create an application to open the .nupkg zip file, extract the license url from the .nuspec file and download the license from this url.
Alternatively you could use the package manager console window inside Visual Studio and with a bit of PowerShell download the license files.
A simple example that gets the license file for all packages in a project is shown below. This would need to be extended to get all the projects in the solution which you should be able to do with the Get-Project cmdlet. This would still require someone to run the script to download the licenses.
$wc = New-Object System.Net.WebClient
Get-Package -ProjectName YourProject | ForEach-Object {
$wc.DownloadFile($_.LicenseUrl, 'd:\licenses\' + $_.Id + ".html")
}

I managed to get the licence information with the following command:
#(#(Get-Project -All | ForEach-Object {
Get-Package -ProjectName $.ProjectName
}) | Select Id -Unique ) | ForEach-Object {
$pkg = $_
$pkgId = $_.Id
if ($pkgId -notlike 'microsoft*') {
$url = Open-PackagePage $pkgId -License -WhatIf -PassThru
Write-Host "$pkgId $url"
}
}

Related

I have installed the "install-dbatools" powershell script, but there is no copy-sqllogin or export-sqllogin function

I have installed the "install-dbatools.ps1" powershell module and it installs successfully, however the functions i am looking for are not there, these functions are "Copy-SQLLogin and "Export-SQLLogin" as per the below
https://www.mssqltips.com/sqlservertip/4654/migrate-sql-server-logins-with-powershell/
I have also run the invoke command below
Invoke-Expression (Invoke-WebRequest http://git.io/vn1hQ).Content
have these commands been deprecated? as i am trying to migrate SQL Logins, roles, permission etc etc to a different server, or how can i achieve this in the best possible way.
SP_HelpRevLogin only does half of this.
Thanks for any assistance
I have downloaded and installed dbatools as per:
https://www.mssqltips.com/sqlservertip/4654/migrate-sql-server-logins-with-powershell/
I have also run the invoke command below as per:
https://gallery.technet.microsoft.com/scriptcenter/Fully-TransferMigrate-SQL-25a0cf05#content/
Invoke-Expression (Invoke-WebRequest http://git.io/vn1hQ).Content
Invoke-Expression (Invoke-WebRequest http://git.io/vn1hQ).Content
i expect the commands Copy-SQLLogin and Export-SQLLogin to be available in order to migrate SQL Logins, roles, permission etc etc to a different server, or how can i achieve this in the best possible way.
The *-SqlLogin tools got renamed some time ago. Try:
Get-Command | ? { $_.Name -like '*-DbaLogin' }
CommandType Name Version Source
----------- ---- ------- ------
Function Copy-DbaLogin 1.0.34 dbatools
Function Export-DbaLogin 1.0.34 dbatools
Function Get-DbaLogin 1.0.34 dbatools
Function New-DbaLogin 1.0.34 dbatools
Function Remove-DbaLogin 1.0.34 dbatools
Function Rename-DbaLogin 1.0.34 dbatools
Function Set-DbaLogin 1.0.34 dbatools

SQL Server LocalDB instance fails to be created/started on Windows 10 build 1809

We have a serious BUG reported by our clients,
regarding the WPF desktop application, which is connecting to the SQL Server 2014 Express LocalDB.
At the startup of the app, the app failed connect to the local DB.
Seems that our (CNogaMedicalLocalDB)local DB instance failed to auto start.
We manually got the local DB instance's info and we saw that the instance is in the "Stopped" state.
Usually the instance is auto start and the state should be "Running"
The local DB log didn't produced any valuable data.
In case we start the local DB manually using CMD the app works fine.
The app works fine on Windows 7, 8 and 10 except the last WIN 10 build 1809 (which is our clients platform)!
The app is being used heavily by many of our other clients around the world.
We cannot reproduce the issue in our Headquarters.
We tried to reproduce the issue on our QA platforms (Virtual Machines) running WIN-10 build 1809.
Apps Technical Details:
WPF.
EF Core version 7.0.0-rc1-final
SQL Server 2014 Express LocalDB version 12.0.2000.8.
Connection string:
data source=(LocalDb)\InstanceLocalDB; Initial Catalog = MyAppDB; Integrated Security=True; MultipleActiveResultSets=True; Connection Timeout = 10
The installation package is built with Advanced Installer version 12.3.1.
5.1. The SQL Server 2014 Express LocalDB is installed together with app and contained as a prerequisite within the installation package.
5.2. The SqlLocalDB Instance creation and starting is performed also during the application's installation via a custom action (PowerShell script which is runs at the final stage of the installation processes):
SqlLocalDB.exe create "SqlLocalDBInstance"
SqlLocalDB.exe start "SqlLocalDBInstance"
Thanks in advance.
Oleg Seider
R&D Department
CNOGA Medical Ltd.
Office: +972-4-6361080 ext.127
www.cnoga.com
According to a link posted by Nickolaj Anderson (who gives credit to a David Segura for getting to the root of this issue and wrote a blog post about it), this problem is caused by Windows 10 1809 lacking two dlls: BCP47Langs.dll and BCP47mrm.dll
The following PowerShell script is posted in the link (and here, just in case the link breaks!) to enable you to update your existing boot images that have already been reloaded from Windows ADK version 1809. It is advised that you make a backup before running the script, as I'm sure you would!
Instructions as given in Nickolaj's article:
Make sure that you have access to a Windows 10 version 1809 64-bit
ISO file and extract it’s content to a location in your site server.
Create the required folders for exporting and mounting:
C:\Temp\Mount\Source
C:\Temp\Mount\Current
C:\Temp\Export
Copy the boot.wim file from the extracted location of Windows 10
version 1809 64-bit to the C:\Temp\Export folder.
Update the $BootImagePath variable in the PowerShell script with the
local path to the boot.wim / winpe.wim found in the data source of your boot image
(remember to include the file name).
Execute the script
Script:
# Variables
$SourceMountPath = "C:\Temp\Mount\Source" # Create this folder
$BootImageMountPath = "C:\Temp\Mount\Current" # Create this folder
$SourceExportFolder = "C:\Temp\Export" # Create this folder
$SourceBootPath = "C:\Temp\Export\boot.wim" # boot.wim file copied to this location from the Windows 10 1809 x64 source media
$BootImagePath = "" # Local path to your boot.wim / winpe.wim file (not boot.PACKAGEID.wim) for your boot image in ConfigMgr
# Export winpe.wim from boot.wim from Windows 10 1809 source files
$ExportImagePath = Join-Path -Path $SourceExportFolder -ChildPath "winpe.wim"
Export-WindowsImage -SourceImagePath $SourceBootPath -DestinationImagePath $ExportImagePath -SourceIndex 1
# Mount exported WinPE image
Mount-WindowsImage -ImagePath $ExportImagePath -Index 1 -Path $SourceMountPath
# Mount boot image
Mount-WindowsImage -ImagePath $BootImagePath -Index 1 -Path $BootImageMountPath
# Copy BCP47*.dll's
$SourceFilePath = Join-Path -Path $SourceMountPath -ChildPath "Windows\System32\*"
$BootImageFilePath = Join-Path -Path $BootImageMountPath -ChildPath "Windows\System32"
Copy-Item -Path $SourceFilePath -Destination $BootImageFilePath -Filter "BCP47*.dll" -Force
# Dismount exported WinPE image
Dismount-WindowsImage -Path $SourceMountPath -Discard
# Dismount boot image
Dismount-WindowsImage -Path $BootImageMountPath -Save
Hope this works for you!
Rachel

Import-Module : The specified module 'activedirectory' was not loaded because no valid module file was found in any module directory

I am having trouble doing an import-module ActiveDirectory on a Server 2008 SP2 (64 bit).
NET Framework 3.5 SP1 is installed
I download the Windows6.0-KB968934-x86.msu (for ADWS)
This file did not install saying that "The update does not apply to my system"
Doing some research (http://anti-american.rssing.com/chan-2091246/all_p15.html) I installed hotfix in KB article 969166 and the above update installed.
After a reboot, I noticed that in services, Active Directory Web Services is running
I opened an administrative PS prompt and performed an Import-Module ActiveDirectory, but...
...I get:
Import-Module : The specified module 'activedirectory' was not loaded because no valid module file was found in any module directory.
At line:1 char:14
+ import-module <<<< activedirectory
+ CategoryInfo : ResourceUnavailable: (activedirectory:String) [Import- Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
If its any help, here's some info in PSModule Path, modules and the version:
PS C:\Windows\system32> $env:PSModulePath
C:\Users\ischmd\Documents\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PS C:\Windows\system32> Get-Module -ListAvailable
ModuleType Name ExportedCommands
---------- ---- ----------------
Manifest BitsTransfer {}
Manifest PSDiagnostics {}
PS C:\Windows\system32> $PSVersionTable.psversion
Major Minor Build Revision
----- ----- ----- --------
2 0 -1 -1
PS C:\Windows\system32> $host.version
Major Minor Build Revision
----- ----- ----- --------
2 0 -1 -1
Any help is greatly appreciated. The main purpose of this is to GET-AdUser command to automate some process but at this point, were stumped. My only conclusion is that this is not possible with Windows 2008 SP2...
AD Powershell module should be listed under installed Features. See image:
.
For non-servers this requires Remote Server Administration Tools for Windows __
Windows 7: http://www.microsoft.com/en-us/download/details.aspx?id=7887
Windows 8: http://www.microsoft.com/en-us/download/details.aspx?id=28972
Windows 10: https://www.microsoft.com/en-au/download/details.aspx?id=45520
The ActiveDirectory module for powershell can be installed by adding the RSAT-AD-Powershell feature.
In an elevated powershell window:
Add-WindowsFeature RSAT-AD-PowerShell
or
Enable-WindowsOptionalFeature -FeatureName ActiveDirectory-Powershell -Online -All
You can install the Active Directory snap-in with Powershell on Windows Server 2012 using the following command:
Install-windowsfeature -name AD-Domain-Services –IncludeManagementTools
This helped me when I had problems with the Features screen due to AppFabric and Windows Update errors.
Even better use implicit remoting to use a module from another Machine!
$s = New-PSSession Server-Name
Invoke-Command -Session $s -ScriptBlock {Import-Module ActiveDirectory}
Import-PSSession -Session $s -Module ActiveDirectory -Prefix REM
This will allow you to use the module off a remote PC for as long as the PSSession is connected.
More Information:
https://technet.microsoft.com/en-us/library/ff720181.aspx
On Windows 10 - This happened for me after the latest update in 2020.
What solved this issue for me was running the following in PowerShell
C:\>Install-Module -Name MicrosoftPowerBIMgmt
This may be an old post, but if anyone is still facing this issue after trying all the above mentioned steps, ensure whether the default path of PowerShell module is specified under the PSModulePath environment variable.
The default path should be %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\
If you don't have the Active Directory module installed on your machine, you need to download the correct Remote Server Administration Tools (RSAT) package for your OS.
https://learn.microsoft.com/en-US/troubleshoot/windows-server/system-management-components/remote-server-administration-tools#rsat-for-windows-10-platform-and-tools-support-matrix
If you are running windows 10 you can download Remote Server Administration Tools for Windows 10 update from here https://www.microsoft.com/en-us/download/details.aspx?id=45520
Once installed run 'import-module ActiveDirectory' using elevated PowerShell.

NuGet DependentUpon files

Let's say I have a WPF Control that I want to deploy as source code transformation via NuGet.
The control has 2 files associated with it: UserControl.xaml.cs and UserControl.xaml.
When I deploy it via NuGet I get the files in the target project, but they don't have the hierarchy structure in the solution explorer. This is due to the fact that NuGet does not know how to add the DependentUpon property in the .csproj file.
Is there a workaround? Is this feature in the roadmap of NuGet?
Thanks
Tal
The answer is Powershell, specifically the Install.ps1 file that will execute automatically upon install if placed within a /tools folder in your NuGet package. Here's code that should do the trick:
param($installPath, $toolsPath, $package, $project)
$buildProject = #([Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($project.FullName))[0]
$file = $buildProject.Xml.Items | Where Include -eq "UserControl.xaml.cs"
$propertyToEdit = $file.Metadata | Where Name -eq "DependentUpon"
if (!$propertyToEdit)
{
$file.AddMetaData("DependentUpon", "UserControl.xaml") | Out-Null
}
$project.Save()
You may not see the change immediately in the Visual Studio interface, but if you unload/reload or close/open the project, you'll see it.

No Silverlight project specified for Silverlight output

I have a very standard silverlight app running under an ASP.NET host. On all dev machines it compiles fine, but on our CI serve, we get this error:
No Silverlight project specified for Silverlight output
But if I log into CI and compile manually with VS2010 it works fine! This is Silverlight 4, .NET 4.0
As I just spent 2 days trying to figure out why this was happening in a Silverlight project I work on, I figured I'd post it here.
In my case, the problem was caused because one of the <ProjectReference> in website's .csproj had a project GUID which didn't match the actual GUID of the project (due to a code reorganization which had occured earlier).
This had nothing to do with the silverlight application or any of its settings. I have no idea why, but somehow this bad reference causes the "CopyFilesToFolders" MSBuild task to get a the same files listed multiple times in the "SourceFiles" list. This causes the first set of copys to succeed followed by a set of "No Silverlight project specified" errors.
Simply removing the bad project reference and re-adding it fixed the GUID and solved the build issue.
A very very bad error message indeed.
Thanks to MerickOWA for posting here, I am sure it saved me hours with the same problem.
I have created a PowerShell script to find the mismatched GUIDs for all projects in a solution. It may save someone else even more hours.
To run it, copy the code below into a text file in the same folder as your solution, rename to .ps1, start up the Powershell console, navigate to the folder containing you solution, then run the script. It will list mis-matched project references, if any.
To fix, open the solution in Visual Studio then remove and re-add the mismatched Project Reference(s).
function validateSolution([string]$slnFileName) {
"Validating solution: " + $slnFileName
# Extract all the c# projects from the solution file
$solutionProjects =
Get-Content $slnFileName | Select-String 'Project\(' | ForEach-Object {
$projectParts = $_ -Split '[,=]' ;
New-Object PSObject -Property #{
Kind = $projectParts[0].Replace('Project("', '').Replace('") ','');
Name = $projectParts[1].Trim('" ');
File = $projectParts[2].Trim('" ');
Guid = $projectParts[3].Trim('" ');
};
} | Where-Object { $_.Kind -eq "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" } # Kind = C# project
# Output list of C# projects to console
# $solutionProjects
# Create HashTable keyed on project GUID
$solutionProjectGuids = #{}
foreach ($project in $solutionProjects) {
$solutionProjectGuids.Add($project.Guid, $project)
}
# Loop through each c# project in the solution
foreach ($project in $solutionProjects) {
[xml]$projectXml = Get-Content $project.File
$projectReferences = $projectXml.Project.ItemGroup | Where-Object { $_.ProjectReference -ne $null }
# Loop through each ProjectReference
foreach($reference in $projectReferences.ChildNodes | Where-Object { $_.Project -ne $null } ) {
# Check the project reference GUID exists in hash table of project GUIDS; if not write error
if (!$solutionProjectGuids.ContainsKey($reference.Project)) {
""
"Bad ProjectReference: Project GUID not found in solution "
"Solution: " + $slnFileName
"Project: " + $project.File
"Reference: " + $reference.Name
"Bad GUID: " + $reference.Project
}
}
}
"Completed solution: " + $slnFileName
}
foreach ($solutionFile in ls *.sln) {
validateSolution $solutionFile
}
If you take a look at the log file that is generated by your build server, you will probably see something like this...
CopySilverlightApplications:
Copying Silverlight applications
Copying <Path>.xap to <Path>.xap
MSBUILD : error : Copying file <Path>.xap failed. No Silverlight project specified for Silverlight output <Path>.xap. [<Path>.csproj]
CopySilverlightApplications is a target that is defined in the following file.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets
It includes this condition which explains why you are not having the problem when building with Visual Studio.
Condition="'$(BuildingInsideVisualStudio)' != 'true'"
I have two build definitions where each builds a different configuration. One of the builds was OK (Release) but the other (Nightly) had the problem that you describe. When I looked at the project file for the silverlight application using an XML editor, I saw that although there was a property group with a condition that evaulated to true for Release - there was none for Nightly.
I manually edited the file by taking a copy of the property group for Release and adjusted the condition and the OutputPath to suit the Nightly build. This resolved the issue.
I noticed afterwards that if I navigated to the Properties page for the Silverlight project in Visual Studio and swapped to the Nightly configuration using the dropdown in the toolbar, that a new PropertyGroup element was automatically generated for that configuration. This would probably also resolve the issue.
I had the same problem. The project built just fine in Debug and Release configuration but I got "No Silverlight project specified for Silverlight output" in the web-project. I also noticed that it was trying to copy the .xap-files from ./bin/Release/ instead of ./bin/Production/.
After removing all Silverlight Applications (tab in project Properties) from the web-project and adding the ClientBin folder as the output path (suggested here) I got a better error message. The problem was that some projects referenced by the web-project were missing the selected configuration. After adding the configuration I could add the Silverlight Applications to the web project again and return the Output path to bin/$(Configuration)/ and still build the solution.
I seemed to be getting duplicate xap file names being generated within the CopySilverlightApplications task which were causing this error. I was able to resolve this issue by making the modification below to the following file. Note the introduction of a new ItemGroup and the reference to it from the SourceFiles attribute in the CopyFilesToFolders Task.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets
<ItemGroup>
<_UniqueSilverlightXapFiles Include="%(_SilverlightXapFiles.FullPath)" />
</ItemGroup>
<!--Copy the outputs to the target folder-->
<CopyFilesToFolders SourceFiles="#(_UniqueSilverlightXapFiles)"
SilverlightApplications="#(_SilverlightApplications)"
ConfigName="$(Configuration)"
Condition="'#(_SilverlightXapFiles)' != ''">
<Output TaskParameter="DestinationFiles" ItemName="_WebApplicationSilverlightXapFiles" />
</CopyFilesToFolders>
To further confuse the matter, I added 2 new projects to our existing solution (a new library and it's associated test project) and the CI build failed with the no silverlight project specified for silverlight output error, which was succeeding 2 days prior. The 2 new projects didn't have the configuration being used by the other projects.
Adding the missing configuration to the 2 new projects via the Solution Configuration Manager fixed it.
Why this would affect the Silverlight projects, which have no relation to these 2 new projects, I have no idea.
I had the same problem. I was making build script, running msbuild on solution.
I was building solution in "Test" configuration, but web project that referenced Silverlight projects kept looking in target bin\Release folder for binaries.
I tried re-adding Silverlight projects, problem was still there.
It turned out problem was to specify Platform in msbuild arguments.
Solution configuration "Test|AnyCPU" and "Test|MixedPlatform" is no same. You will find that both Configuration and Platform has to be equal to same pair defined in project file. I don't know what Platform was msbuild taking by default, but I know it jumped to Release folder instead.
Anyway, I added /p:Platform="Any CPU" to msbuild arguments.
After carefully reviewing the configuration that was being built for CI, I found that one of the projects being referenced by my web project was set up to build with a wrong configuration. My CI build was set up to build for Staging (Any CPU) and one of my .projects that was being referenced by the Web project was set up to build using Release configuration. Once I updated the Configuration to be Staging, the CI build completed successfully

Resources