mirror of https://github.com/microsoft/vcpkg.git
54 lines
2.2 KiB
Plaintext
54 lines
2.2 KiB
Plaintext
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
<UsingTask TaskName="GetVcpkgEnvVars" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
|
|
<ParameterGroup>
|
|
<VcpkgEnvVars Output="true" ParameterType="System.String" />
|
|
</ParameterGroup>
|
|
<Task>
|
|
<Using Namespace="System" />
|
|
<Using Namespace="System.Text" />
|
|
<Using Namespace="System.Collections" />
|
|
<Using Namespace="System.Collections.Generic" />
|
|
<Code Type="Fragment" Language="cs">
|
|
<![CDATA[
|
|
var sb = new StringBuilder();
|
|
|
|
// VCPKG_KEEP_ENV_VARS lists additional variable names (semicolon-separated)
|
|
// that should be forwarded
|
|
var keepVars = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
|
string keepList = Environment.GetEnvironmentVariable("VCPKG_KEEP_ENV_VARS");
|
|
if (!string.IsNullOrEmpty(keepList))
|
|
{
|
|
foreach (var name in keepList.Split(';'))
|
|
{
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
keepVars.Add(name.Trim());
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (DictionaryEntry de in Environment.GetEnvironmentVariables())
|
|
{
|
|
string key = de.Key.ToString();
|
|
// Filter for both prefixes, plus anything explicitly kept via VCPKG_KEEP_ENV_VARS
|
|
if (key.StartsWith("VCPKG_", StringComparison.OrdinalIgnoreCase) ||
|
|
key.StartsWith("X_VCPKG_", StringComparison.OrdinalIgnoreCase) ||
|
|
keepVars.Contains(key))
|
|
{
|
|
string val = de.Value.ToString();
|
|
|
|
// To handle semicolons inside the value, we escape them
|
|
// so MSBuild doesn't split the value into a new property.
|
|
val = val.Replace(";", "%3B");
|
|
|
|
if (sb.Length > 0) sb.Append("____");
|
|
sb.Append(key + "=" + val);
|
|
}
|
|
}
|
|
VcpkgEnvVars = sb.ToString();
|
|
]]>
|
|
</Code>
|
|
</Task>
|
|
</UsingTask>
|
|
</Project>
|