Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/Tasks.UnitTests/AxTlbBaseTask_Tests.cs
Comment thread
AlesProkop marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void KeyFile()
Assert.Equal(badParameterValue, t.KeyFile); // "New KeyFile value should be set"
CommandLine.ValidateHasParameter(
t,
@"/keyfile:" + badParameterValue,
@"/keyfile:" + Path.GetFullPath(badParameterValue),
false /* no response file */);
Utilities.ExecuteTaskAndVerifyLogContainsErrorFromResource(t, "AxTlbBaseTask.InvalidKeyFileSpecified", t.KeyFile);

Expand Down
8 changes: 4 additions & 4 deletions src/Tasks.UnitTests/TlbImp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public void ReferenceFiles()
t.ReferenceFiles = new string[] { "File1.dll", "File2.dll" };
CommandLine.ValidateHasParameter(
t,
"/reference:File1.dll",
"/reference:" + Path.GetFullPath("File1.dll"),
false /* no response file */);
CommandLine.ValidateHasParameter(
t,
"/reference:File2.dll",
"/reference:" + Path.GetFullPath("File2.dll"),
false /* no response file */);
Comment thread
AlesProkop marked this conversation as resolved.
}
/// <summary>
Expand All @@ -61,7 +61,7 @@ public void TypeLibName()

t.TypeLibName = testParameterValue;
Assert.Equal(testParameterValue, t.TypeLibName); // "New TypeLibName value should be set"
CommandLine.ValidateHasParameter(t, testParameterValue, false /* no response file */);
CommandLine.ValidateHasParameter(t, Path.GetFullPath(testParameterValue), false /* no response file */);
}

/// <summary>
Expand Down Expand Up @@ -167,7 +167,7 @@ public void OutputAssembly()
Assert.Equal(testParameterValue, t.OutputAssembly); // "New OutputAssembly value should be set"
CommandLine.ValidateHasParameter(
t,
@"/out:" + testParameterValue,
@"/out:" + Path.GetFullPath(testParameterValue),
false /* no response file */);
}

Expand Down
20 changes: 12 additions & 8 deletions src/Tasks/AxTlbBaseTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@ protected internal override void AddCommandLineCommands(CommandLineBuilderExtens
protected override string GenerateFullPathToTool()
{
string pathToTool = SdkToolsPathUtility.GeneratePathToTool(
Comment thread
AlesProkop marked this conversation as resolved.
SdkToolsPathUtility.FileInfoExists,
f => string.IsNullOrEmpty(f)
? SdkToolsPathUtility.FileInfoExists(f)
: SdkToolsPathUtility.FileInfoExists(TaskEnvironment.GetAbsolutePath(f)),
Comment thread
AlesProkop marked this conversation as resolved.
Outdated
Utilities.ProcessorArchitecture.CurrentProcessArchitecture,
SdkToolsPath,
ToolName,
Log,
true);

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

/// <summary>
Expand All @@ -125,8 +127,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) || !FileSystems.Default.DirectoryExists(TaskEnvironment.GetAbsolutePath(ToolPath))) &&
(string.IsNullOrEmpty(SdkToolsPath) || !FileSystems.Default.DirectoryExists(TaskEnvironment.GetAbsolutePath(SdkToolsPath))))
{
Log.LogErrorWithCodeFromResources("AxTlbBaseTask.SdkOrToolPathNotSpecifiedOrInvalid", SdkToolsPath ?? "", ToolPath ?? "");
return false;
Expand Down Expand Up @@ -155,13 +157,14 @@ private void AddStrongNameOptions(CommandLineBuilderExtension commandLine)
// throw an error.
//
// So use /publickey if that's all our KeyFile contains, but KeyFile otherwise.
string absoluteKeyFile = string.IsNullOrEmpty(KeyFile) ? KeyFile : TaskEnvironment.GetAbsolutePath(KeyFile).Value;
Comment thread
AlesProkop marked this conversation as resolved.
Outdated
if (_delaySigningAndKeyFileOnlyContainsPublicKey)
{
commandLine.AppendSwitchIfNotNull("/publickey:", KeyFile);
commandLine.AppendSwitchIfNotNull("/publickey:", absoluteKeyFile);
}
else
{
commandLine.AppendSwitchIfNotNull("/keyfile:", KeyFile);
commandLine.AppendSwitchIfNotNull("/keyfile:", absoluteKeyFile);
}

commandLine.AppendSwitchIfNotNull("/keycontainer:", KeyContainer);
Expand All @@ -179,7 +182,7 @@ private bool ValidateStrongNameParameters()
// Make sure that if KeyFile is defined, it's a real file.
if (!String.IsNullOrEmpty(KeyFile))
{
if (FileSystems.Default.FileExists(KeyFile))
if (FileSystems.Default.FileExists(TaskEnvironment.GetAbsolutePath(KeyFile)))
{
keyFileExists = true;
}
Expand Down Expand Up @@ -216,7 +219,8 @@ private bool ValidateStrongNameParameters()

try
{
StrongNameUtils.GetStrongNameKey(Log, KeyFile, KeyContainer, out keyPair, out publicKey);
string keyFileForRead = string.IsNullOrEmpty(KeyFile) ? KeyFile : TaskEnvironment.GetAbsolutePath(KeyFile).Value;
StrongNameUtils.GetStrongNameKey(Log, keyFileForRead, KeyContainer, out keyPair, out publicKey);
}
catch (StrongNameException e)
{
Expand Down
17 changes: 14 additions & 3 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 Expand Up @@ -236,15 +239,15 @@ public string[] ReferenceFiles
protected internal override void AddCommandLineCommands(CommandLineBuilderExtension commandLine)
{
// .ocx file being imported
commandLine.AppendFileNameIfNotNull(TypeLibName);
commandLine.AppendFileNameIfNotNull(AbsolutizeIfNotEmpty(TypeLibName));
Comment thread
AlesProkop marked this conversation as resolved.
Outdated

// options
Comment thread
AlesProkop marked this conversation as resolved.
commandLine.AppendSwitchIfNotNull("/asmversion:", AssemblyVersion?.ToString());
commandLine.AppendSwitchIfNotNull("/namespace:", AssemblyNamespace);
commandLine.AppendSwitchIfNotNull("/machine:", Machine);
commandLine.AppendWhenTrue("/noclassmembers", Bag, "PreventClassMembers");
commandLine.AppendWhenTrue("/nologo", Bag, "NoLogo");
commandLine.AppendSwitchIfNotNull("/out:", OutputAssembly);
commandLine.AppendSwitchIfNotNull("/out:", AbsolutizeIfNotEmpty(OutputAssembly));
commandLine.AppendWhenTrue("/silent", Bag, "Silent");
commandLine.AppendWhenTrue("/sysarray", Bag, "SafeArrayAsSystemArray");
commandLine.AppendSwitchIfNotNull("/transform:", ConvertTransformFlagsToCommandLineCommand(Transform));
Expand All @@ -253,13 +256,21 @@ protected internal override void AddCommandLineCommands(CommandLineBuilderExtens
{
foreach (var referenceFile in ReferenceFiles)
{
commandLine.AppendSwitchIfNotNull("/reference:", referenceFile);
commandLine.AppendSwitchIfNotNull("/reference:", AbsolutizeIfNotEmpty(referenceFile));
}
}

base.AddCommandLineCommands(commandLine);
}

/// <summary>
/// Returns the absolutized form of <paramref name="path"/> when it is non-empty,
/// or the original value when null/empty (preserves prior null/empty handling of
/// the CommandLineBuilderExtension Append*IfNotNull helpers).
/// </summary>
private string AbsolutizeIfNotEmpty(string path)
=> string.IsNullOrEmpty(path) ? path : TaskEnvironment.GetAbsolutePath(path).Value;

/// <summary>
/// Validates the parameters passed to the task
/// </summary>
Expand Down
Loading