本文整理汇总了C#中Microsoft.Build.Shared.AssemblyNameExtension.GetPublicKeyToken方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyNameExtension.GetPublicKeyToken方法的具体用法?C# AssemblyNameExtension.GetPublicKeyToken怎么用?C# AssemblyNameExtension.GetPublicKeyToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Shared.AssemblyNameExtension
的用法示例。
在下文中一共展示了AssemblyNameExtension.GetPublicKeyToken方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLocation
internal static string GetLocation(AssemblyNameExtension strongName, ProcessorArchitecture targetProcessorArchitecture, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVersion, bool fullFusionName, Microsoft.Build.Shared.FileExists fileExists, GetPathFromFusionName getPathFromFusionName, GetGacEnumerator getGacEnumerator, bool specificVersion)
{
string str = null;
if (((strongName.GetPublicKeyToken() == null) || (strongName.GetPublicKeyToken().Length == 0)) && (strongName.FullName.IndexOf("PublicKeyToken", StringComparison.OrdinalIgnoreCase) != -1))
{
return str;
}
getPathFromFusionName = getPathFromFusionName ?? pathFromFusionName;
getGacEnumerator = getGacEnumerator ?? gacEnumerator;
if (!strongName.HasProcessorArchitectureInFusionName)
{
if ((targetProcessorArchitecture != ProcessorArchitecture.MSIL) && (targetProcessorArchitecture != ProcessorArchitecture.None))
{
string str2 = ResolveAssemblyReference.ProcessorArchitectureToString(targetProcessorArchitecture);
if (fullFusionName)
{
str = CheckForFullFusionNameInGac(strongName, str2, getPathFromFusionName);
}
else
{
str = GetLocationImpl(strongName, str2, getRuntimeVersion, targetedRuntimeVersion, fileExists, getPathFromFusionName, getGacEnumerator, specificVersion);
}
if ((str != null) && (str.Length > 0))
{
return str;
}
}
if (fullFusionName)
{
str = CheckForFullFusionNameInGac(strongName, "MSIL", getPathFromFusionName);
}
else
{
str = GetLocationImpl(strongName, "MSIL", getRuntimeVersion, targetedRuntimeVersion, fileExists, getPathFromFusionName, getGacEnumerator, specificVersion);
}
if ((str != null) && (str.Length > 0))
{
return str;
}
}
if (fullFusionName)
{
str = CheckForFullFusionNameInGac(strongName, null, getPathFromFusionName);
}
else
{
str = GetLocationImpl(strongName, null, getRuntimeVersion, targetedRuntimeVersion, fileExists, getPathFromFusionName, getGacEnumerator, specificVersion);
}
if ((str != null) && (str.Length > 0))
{
return str;
}
return null;
}
示例2: CheckForFullFusionNameInGac
/// <summary>
/// Given a strong name, find its path in the GAC.
/// </summary>
/// <param name="strongName">The strong name.</param>
/// <param name="targetProcessorArchitecture">Like x86 or IA64\AMD64.</param>
/// <param name="getRuntimeVersion">Delegate to get the runtime version from a file path</param>
/// <param name="targetedRuntimeVersion">What version of the runtime are we targeting</param>
/// <param name="fullFusionName">Are we guranteed to have a full fusion name. This really can only happen if we have already resolved the assembly</param>
/// <returns>The path to the assembly. Empty if none exists.</returns>
internal static string GetLocation
(
IBuildEngine4 buildEngine,
AssemblyNameExtension strongName,
ProcessorArchitecture targetProcessorArchitecture,
GetAssemblyRuntimeVersion getRuntimeVersion,
Version targetedRuntimeVersion,
bool fullFusionName,
FileExists fileExists,
GetPathFromFusionName getPathFromFusionName,
GetGacEnumerator getGacEnumerator,
bool specificVersion
)
{
ConcurrentDictionary<AssemblyNameExtension, string> fusionNameToResolvedPath = null;
bool useGacRarCache = Environment.GetEnvironmentVariable("MSBUILDDISABLEGACRARCACHE") == null;
if (buildEngine != null && useGacRarCache)
{
string key = "44d78b60-3bbe-48fe-9493-04119ebf515f" + "|" + targetProcessorArchitecture.ToString() + "|" + targetedRuntimeVersion.ToString() + "|" + fullFusionName.ToString() + "|" + specificVersion.ToString();
fusionNameToResolvedPath = buildEngine.GetRegisteredTaskObject(key, RegisteredTaskObjectLifetime.Build) as ConcurrentDictionary<AssemblyNameExtension, string>;
if (fusionNameToResolvedPath == null)
{
fusionNameToResolvedPath = new ConcurrentDictionary<AssemblyNameExtension, string>(AssemblyNameComparer.GenericComparer);
buildEngine.RegisterTaskObject(key, fusionNameToResolvedPath, RegisteredTaskObjectLifetime.Build, true /* dispose early ok*/);
}
else
{
if (fusionNameToResolvedPath.ContainsKey(strongName))
{
string fusionName = null;
fusionNameToResolvedPath.TryGetValue(strongName, out fusionName);
return fusionName;
}
}
}
// Optimize out the case where the public key token is null, if it is null it is not a strongly named assembly and CANNOT be in the gac.
// also passing it would cause the gac enumeration method to throw an exception indicating the assembly is not a strongnamed assembly.
string location = null;
// If the publickeyToken is null and the publickeytoken is in the fusion name then this means we are passing in a null or empty PublicKeyToken and then this cannot possibly be in the gac.
if ((strongName.GetPublicKeyToken() == null || strongName.GetPublicKeyToken().Length == 0) && strongName.FullName.IndexOf("PublicKeyToken", StringComparison.OrdinalIgnoreCase) != -1)
{
if (fusionNameToResolvedPath != null)
{
fusionNameToResolvedPath.TryAdd(strongName, location);
}
return location;
}
// A delegate was not passed in to use the default one
getPathFromFusionName = getPathFromFusionName ?? pathFromFusionName;
// A delegate was not passed in to use the default one
getGacEnumerator = getGacEnumerator ?? gacEnumerator;
// If we have no processor architecture set then we can tryout a number of processor architectures.
if (!strongName.HasProcessorArchitectureInFusionName)
{
if (targetProcessorArchitecture != ProcessorArchitecture.MSIL && targetProcessorArchitecture != ProcessorArchitecture.None)
{
string processorArchitecture = ResolveAssemblyReference.ProcessorArchitectureToString(targetProcessorArchitecture);
// Try processor specific first.
if (fullFusionName)
{
location = CheckForFullFusionNameInGac(strongName, processorArchitecture, getPathFromFusionName);
}
else
{
location = GetLocationImpl(strongName, processorArchitecture, getRuntimeVersion, targetedRuntimeVersion, fileExists, getPathFromFusionName, getGacEnumerator, specificVersion);
}
if (location != null && location.Length > 0)
{
if (fusionNameToResolvedPath != null)
{
fusionNameToResolvedPath.TryAdd(strongName, location);
}
return location;
}
}
// Next, try MSIL
if (fullFusionName)
{
location = CheckForFullFusionNameInGac(strongName, "MSIL", getPathFromFusionName);
}
else
{
//.........这里部分代码省略.........
示例3: TestAssemblyPatialMatchSimpleNamePublicKeyToken
public void TestAssemblyPatialMatchSimpleNamePublicKeyToken()
{
AssemblyNameExtension assemblyNameToMatchPublicToken = new AssemblyNameExtension("System.Xml, PublicKeyToken=b03f5f7f11d50a3a");
AssemblyNameExtension assemblyNameToNotMatch = new AssemblyNameExtension("System.Xml, PublicKeyToken=b03f5f7f11d50a3b");
AssemblyNameExtension assemblyMatchNoVersion = new AssemblyNameExtension("System.Xml");
foreach (string assembly in assembliesForPartialMatch)
{
AssemblyNameExtension assemblyToCompare = new AssemblyNameExtension(assembly);
// If there is a version make sure the assembly name with the correct publicKeyToken matches
// Make sure the assembly with the wrong publicKeyToken does not match
if (assemblyToCompare.GetPublicKeyToken() != null)
{
Assert.IsTrue(assemblyNameToMatchPublicToken.PartialNameCompare(assemblyToCompare));
Assert.IsTrue(assemblyNameToMatchPublicToken.PartialNameCompare(assemblyToCompare, PartialComparisonFlags.SimpleName | PartialComparisonFlags.PublicKeyToken));
Assert.IsFalse(assemblyNameToNotMatch.PartialNameCompare(assemblyToCompare));
Assert.IsFalse(assemblyNameToNotMatch.PartialNameCompare(assemblyToCompare, PartialComparisonFlags.SimpleName | PartialComparisonFlags.PublicKeyToken));
// Matches because publicKeyToken is not specified
Assert.IsTrue(assemblyMatchNoVersion.PartialNameCompare(assemblyToCompare));
Assert.IsTrue(assemblyMatchNoVersion.PartialNameCompare(assemblyToCompare, PartialComparisonFlags.SimpleName | PartialComparisonFlags.PublicKeyToken));
}
else
{
// If there is no version make names with a publicKeyToken specified do not match
Assert.IsFalse(assemblyNameToMatchPublicToken.PartialNameCompare(assemblyToCompare));
Assert.IsFalse(assemblyNameToMatchPublicToken.PartialNameCompare(assemblyToCompare, PartialComparisonFlags.SimpleName | PartialComparisonFlags.PublicKeyToken));
Assert.IsFalse(assemblyNameToNotMatch.PartialNameCompare(assemblyToCompare));
Assert.IsFalse(assemblyNameToNotMatch.PartialNameCompare(assemblyToCompare, PartialComparisonFlags.SimpleName | PartialComparisonFlags.PublicKeyToken));
// Matches because publicKeyToken is not specified
Assert.IsTrue(assemblyMatchNoVersion.PartialNameCompare(assemblyToCompare));
Assert.IsTrue(assemblyMatchNoVersion.PartialNameCompare(assemblyToCompare, PartialComparisonFlags.SimpleName | PartialComparisonFlags.PublicKeyToken));
}
}
}
示例4: ComparePublicKeyToken
internal bool ComparePublicKeyToken(AssemblyNameExtension that)
{
byte[] publicKeyToken = this.GetPublicKeyToken();
byte[] bPKT = that.GetPublicKeyToken();
return ComparePublicKeyTokens(publicKeyToken, bPKT);
}
示例5: ComparePublicKeyToken
/// <summary>
/// Allows the comparison of just the PublicKeyToken
/// </summary>
internal bool ComparePublicKeyToken(AssemblyNameExtension that)
{
// Do the PKTs match?
byte[] aPKT = GetPublicKeyToken();
byte[] bPKT = that.GetPublicKeyToken();
return ComparePublicKeyTokens(aPKT, bPKT);
}