Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Tasks/AxImp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;

using Microsoft.Build.Framework;

#nullable disable

namespace Microsoft.Build.Tasks
Expand All @@ -16,6 +18,7 @@ public sealed partial class ResolveComReference
/// Defines the "AxImp" MSBuild task, which enables using AxImp.exe
/// to generate Windows Forms wrappers for ActiveX controls.
/// </summary>
[MSBuildMultiThreadableTask]
internal class AxImp : AxTlbBaseTask
{
#region Properties
Expand Down
47 changes: 41 additions & 6 deletions src/Tasks/AxTlbBaseTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ protected internal override void AddCommandLineCommands(CommandLineBuilderExtens
protected override string GenerateFullPathToTool()
{
string pathToTool = SdkToolsPathUtility.GeneratePathToTool(
Comment thread
AlesProkop marked this conversation as resolved.
SdkToolsPathUtility.FileInfoExists,
FileInfoExists,
Utilities.ProcessorArchitecture.CurrentProcessArchitecture,
SdkToolsPath,
ToolName,
Log,
true);

return pathToTool;
return string.IsNullOrEmpty(pathToTool) ? pathToTool : TaskEnvironment.GetAbsolutePath(pathToTool).Value;
}

/// <summary>
Expand All @@ -125,8 +125,8 @@ protected override bool ValidateParameters()
{
// Verify that a path for the tool exists -- if the tool doesn't exist in it
// we'll worry about that later
if ((String.IsNullOrEmpty(ToolPath) || !FileSystems.Default.DirectoryExists(ToolPath)) &&
(String.IsNullOrEmpty(SdkToolsPath) || !FileSystems.Default.DirectoryExists(SdkToolsPath)))
if ((string.IsNullOrEmpty(ToolPath) || !DirectoryExists(ToolPath)) &&
(string.IsNullOrEmpty(SdkToolsPath) || !DirectoryExists(SdkToolsPath)))
{
Log.LogErrorWithCodeFromResources("AxTlbBaseTask.SdkOrToolPathNotSpecifiedOrInvalid", SdkToolsPath ?? "", ToolPath ?? "");
return false;
Expand Down Expand Up @@ -155,6 +155,9 @@ private void AddStrongNameOptions(CommandLineBuilderExtension commandLine)
// throw an error.
//
// So use /publickey if that's all our KeyFile contains, but KeyFile otherwise.
// The KeyFile path is passed verbatim to the spawned tool; ToolTask sets the child
Comment thread
AlesProkop marked this conversation as resolved.
Outdated
// process's WorkingDirectory to the project directory (via TaskEnvironment), so the
// tool resolves relative paths correctly without us absolutizing here.
if (_delaySigningAndKeyFileOnlyContainsPublicKey)
{
commandLine.AppendSwitchIfNotNull("/publickey:", KeyFile);
Expand All @@ -175,11 +178,14 @@ private void AddStrongNameOptions(CommandLineBuilderExtension commandLine)
private bool ValidateStrongNameParameters()
{
bool keyFileExists = false;
string keyFileForRead = null;

// Make sure that if KeyFile is defined, it's a real file.
if (!String.IsNullOrEmpty(KeyFile))
{
if (FileSystems.Default.FileExists(KeyFile))
keyFileForRead = GetAbsolutePathIfValid(KeyFile);

if (keyFileForRead != null && FileSystems.Default.FileExists(keyFileForRead))
{
keyFileExists = true;
}
Expand Down Expand Up @@ -216,7 +222,7 @@ private bool ValidateStrongNameParameters()

try
{
StrongNameUtils.GetStrongNameKey(Log, KeyFile, KeyContainer, out keyPair, out publicKey);
StrongNameUtils.GetStrongNameKey(Log, keyFileForRead, KeyFile, KeyContainer, out keyPair, out publicKey);
}
catch (StrongNameException e)
{
Expand Down Expand Up @@ -260,6 +266,35 @@ private bool ValidateStrongNameParameters()
return true;
}

private bool DirectoryExists(string path)
{
Comment thread
AlesProkop marked this conversation as resolved.
Outdated
string absolutePath = GetAbsolutePathIfValid(path);
return absolutePath != null && FileSystems.Default.DirectoryExists(absolutePath);
}

private bool FileInfoExists(string path)
{
string absolutePath = GetAbsolutePathIfValid(path);
return absolutePath != null && SdkToolsPathUtility.FileInfoExists(absolutePath);
}

private string GetAbsolutePathIfValid(string path)
Comment thread
AlesProkop marked this conversation as resolved.
Outdated
{
if (string.IsNullOrEmpty(path))
{
return null;
}

try
{
return TaskEnvironment.GetAbsolutePath(path).Value;
}
catch (ArgumentException)
{
return null;
}
}

#endregion // ToolTask Members
}
}
24 changes: 20 additions & 4 deletions src/Tasks/StrongNameUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ internal static class StrongNameUtils
/// Reads contents of a key file. Reused from vsdesigner code.
/// </summary>
internal static void ReadKeyFile(TaskLoggingHelper log, string keyFile, out StrongNameKeyPair keyPair, out byte[] publicKey)
{
ReadKeyFile(log, keyFile, keyFile, out keyPair, out publicKey);
}

/// <summary>
/// Reads contents of a key file. Reused from vsdesigner code.
/// </summary>
internal static void ReadKeyFile(TaskLoggingHelper log, string keyFile, string keyFileDisplayName, out StrongNameKeyPair keyPair, out byte[] publicKey)
{
// Initialize parameters
keyPair = null;
Expand All @@ -55,19 +63,19 @@ internal static void ReadKeyFile(TaskLoggingHelper log, string keyFile, out Stro
}
catch (ArgumentException e)
{
log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", keyFile);
log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", keyFileDisplayName);
log.LogErrorFromException(e);
throw new StrongNameException(e);
}
catch (IOException e)
{
log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", keyFile);
log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", keyFileDisplayName);
log.LogErrorFromException(e);
throw new StrongNameException(e);
}
catch (SecurityException e)
{
log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", keyFile);
log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", keyFileDisplayName);
log.LogErrorFromException(e);
throw new StrongNameException(e);
}
Expand Down Expand Up @@ -95,6 +103,14 @@ internal static void ReadKeyFile(TaskLoggingHelper log, string keyFile, out Stro
/// Given a key file or container, extract private/public key data. Reused from vsdesigner code.
/// </summary>
internal static void GetStrongNameKey(TaskLoggingHelper log, string keyFile, string keyContainer, out StrongNameKeyPair keyPair, out byte[] publicKey)
{
GetStrongNameKey(log, keyFile, keyFile, keyContainer, out keyPair, out publicKey);
Comment thread
AlesProkop marked this conversation as resolved.
Outdated
}

/// <summary>
/// Given a key file or container, extract private/public key data. Reused from vsdesigner code.
/// </summary>
internal static void GetStrongNameKey(TaskLoggingHelper log, string keyFile, string keyFileDisplayName, string keyContainer, out StrongNameKeyPair keyPair, out byte[] publicKey)
Comment thread
AlesProkop marked this conversation as resolved.
Outdated
{
// Gets either a strong name key pair from the key file or a key container.
// If keyFile and keyContainer are both null/zero length then returns null.
Expand Down Expand Up @@ -123,7 +139,7 @@ internal static void GetStrongNameKey(TaskLoggingHelper log, string keyFile, str
}
else if (!string.IsNullOrEmpty(keyFile))
{
ReadKeyFile(log, keyFile, out keyPair, out publicKey);
ReadKeyFile(log, keyFile, keyFileDisplayName, out keyPair, out publicKey);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Tasks/TlbImp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;

using Microsoft.Build.Framework;

#nullable disable

namespace Microsoft.Build.Tasks
Expand Down Expand Up @@ -40,6 +42,7 @@ internal enum TlbImpTransformFlags
/// Defines the "TlbImp" MSBuild task, which enables using TlbImp.exe
/// to generate assemblies from type libraries.
/// </summary>
[MSBuildMultiThreadableTask]
internal class TlbImp : AxTlbBaseTask
{
#region Properties
Expand Down