Last active
November 11, 2018 14:51
-
-
Save AlexBAV/61598f8a7f21e65a0299cdcc6ccbc7e0 to your computer and use it in GitHub Desktop.
Script to fix NuGet packages exported by vcpkg.exe export --nuget command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fix-NuGetPackage.ps1 | |
# This script fixes NuGet packages exported by vcpkg.exe utility | |
# In the current version (see issue #3954) multiple exported NuGet packages | |
# cannot be used in a single project | |
# | |
# This script fixes it by introducing a "namespace" to MsBuild properties | |
# used by exported NuGet packages | |
# First parameter is a NuGet package name with extension | |
# Second parameter is a namespace prefix (should be valid MsBuild property name) | |
param([string] $package_name, [string] $prefix) | |
$zip_file = $package_name + ".zip" | |
$temp_folder_name = $package_name + "-folder" | |
# Expand-Archive requires archive to have .zip extension | |
Rename-Item $package_name $zip_file | |
Expand-Archive -LiteralPath $zip_file -DestinationPath $temp_folder_name | |
$targets_file = "$temp_folder_name\scripts\buildsystems\msbuild\vcpkg.targets" | |
[string] $targets = Get-Content $targets_file | |
$targets = ($targets).Replace('$(Vcpkg', '$(' + $prefix + '_Vcpkg').Replace('<Vcpkg', '<' + $prefix + '_Vcpkg').Replace('</Vcpkg', '</' + $prefix + '_Vcpkg') | |
Set-Content $targets_file $targets | |
Remove-Item $zip_file | |
Compress-Archive $temp_folder_name\* -DestinationPath $zip_file -CompressionLevel Optimal | |
Rename-Item $zip_file $package_name | |
Remove-Item $temp_folder_name -Recurse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.\vcpkg.exe install nlohmann-json nlohmann-json:x64-windows | |
.\vcpkg.exe export --nuget --nuget-id=nlohmann-json --nuget-version=3.4.0 nlohmann-json nlohmann-json:x64-windows | |
.\Fix-NuGetPackage.ps1 nlohmann-json.3.4.0.nupkg nlohmann |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment