You can add install script to your NuGet package to add an alias. But the consumer of the package could not refuse to add an alias. Here is the code you can use in the script. I'm not the best in PowerShell, so there may be a better way to do this :)
param($installPath, $toolsPath, $package, $project)
$alias = 'MyAlias'
Add-Type -AssemblyName Microsoft.Build
$projectObject = New-Object Microsoft.Build.Evaluation.Project($project.FullName)
$referenceItems = $projectObject.Items | where ItemType -eq "Reference"
$item = $referenceItems | select @{Name='Reference'; Expression={$_}},@{Name='AssemblyName'; Expression={(New-Object System.Reflection.AssemblyName($_.UnevaluatedInclude)).Name}} | where AssemblyName -eq $package.Id | select Reference
if (($item.Reference.Metadata | where Name -eq 'Aliases') -eq $null) {
$item.Reference.SetMetadataValue('Aliases', $alias)
$projectObject.Save()
}
$projectObject.ProjectCollection.UnloadAllProjects()
source
share