-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathAxImp.cs
160 lines (138 loc) · 6.21 KB
/
AxImp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
#nullable disable
namespace Microsoft.Build.Tasks
{
/// <summary>
/// Main class for the COM reference resolution task
/// </summary>
public sealed partial class ResolveComReference
{
/// <summary>
/// Defines the "AxImp" MSBuild task, which enables using AxImp.exe
/// to generate Windows Forms wrappers for ActiveX controls.
/// </summary>
internal class AxImp : AxTlbBaseTask
{
#region Properties
/*
Microsoft (R) .NET ActiveX Control to Windows Forms Assembly Generator
[Microsoft .Net Framework, Version 4.0.10719.0]
Copyright (c) Microsoft Corporation. All rights reserved.
Generates a Windows Forms Control that wraps ActiveX controls defined in the given OcxName.
Usage:
AxImp OcxName [Options]
Options:
/out:FileName File name of assembly to be produced
/publickey:FileName File containing strong name public key
/keyfile:FileName File containing strong name key pair
/keycontainer:FileName Key container holding strong name key pair
/delaysign Force strong name delay signing
Used with /keyfile, /keycontainer or /publickey
/source Generate C# source code for Windows Forms wrapper
/rcw:FileName Assembly to use for Runtime Callable Wrapper rather than generating new one.
Multiple instances may be specified. Current directory is used for relative paths.
/nologo Prevents AxImp from displaying logo
/silent Prevents AxImp from displaying success message
/verbose Displays extra information
/? or /help Display this usage message
*/
/// <summary>
/// .ocx File the ActiveX controls being wrapped are defined in.
/// </summary>
public string ActiveXControlName
{
get => (string)Bag[nameof(ActiveXControlName)];
set => Bag[nameof(ActiveXControlName)] = value;
}
/// <summary>
/// If true, will generate C# source code for the Windows Forms wrapper.
/// </summary>
public bool GenerateSource
{
get => GetBoolParameterWithDefault(nameof(GenerateSource), false);
set => Bag[nameof(GenerateSource)] = value;
}
/// <summary>
/// If true, suppresses displaying the logo
/// </summary>
public bool NoLogo
{
get => GetBoolParameterWithDefault(nameof(NoLogo), false);
set => Bag[nameof(NoLogo)] = value;
}
/// <summary>
/// File name of assembly to be produced.
/// </summary>
public string OutputAssembly
{
get => (string)Bag[nameof(OutputAssembly)];
set => Bag[nameof(OutputAssembly)] = value;
}
/// <summary>
/// Name of assembly to use as a RuntimeCallableWrapper instead of generating one.
/// </summary>
public string RuntimeCallableWrapperAssembly
{
get => (string)Bag[nameof(RuntimeCallableWrapperAssembly)];
set => Bag[nameof(RuntimeCallableWrapperAssembly)] = value;
}
/// <summary>
/// If true, prevents AxImp from displaying success message.
/// </summary>
public bool Silent
{
get => GetBoolParameterWithDefault(nameof(Silent), false);
set => Bag[nameof(Silent)] = value;
}
/// <summary>
/// If true, AxImp prints more information.
/// </summary>
public bool Verbose
{
get => GetBoolParameterWithDefault(nameof(Verbose), false);
set => Bag[nameof(Verbose)] = value;
}
#endregion // Properties
#region ToolTask Members
/// <summary>
/// Returns the name of the tool to execute
/// </summary>
protected override string ToolName => "AxImp.exe";
/// <summary>
/// Fills the provided CommandLineBuilderExtension with all the command line options used when
/// executing this tool
/// </summary>
/// <param name="commandLine">Gets filled with command line commands</param>
protected internal override void AddCommandLineCommands(CommandLineBuilderExtension commandLine)
{
// .ocx file being imported
commandLine.AppendFileNameIfNotNull(ActiveXControlName);
// options
commandLine.AppendWhenTrue("/nologo", Bag, "NoLogo");
commandLine.AppendSwitchIfNotNull("/out:", OutputAssembly);
commandLine.AppendSwitchIfNotNull("/rcw:", RuntimeCallableWrapperAssembly);
commandLine.AppendWhenTrue("/silent", Bag, "Silent");
commandLine.AppendWhenTrue("/source", Bag, "GenerateSource");
commandLine.AppendWhenTrue("/verbose", Bag, "Verbose");
base.AddCommandLineCommands(commandLine);
}
/// <summary>
/// Validates the parameters passed to the task
/// </summary>
/// <returns>True if parameters are valid</returns>
protected override bool ValidateParameters()
{
// Verify that we were actually passed a .ocx to import
if (String.IsNullOrEmpty(ActiveXControlName))
{
Log.LogErrorWithCodeFromResources("AxImp.NoInputFileSpecified");
return false;
}
return base.ValidateParameters();
}
#endregion // ToolTask Members
}
}
}