Move the responsibility of wrapping the binary interfaces from mbahost to the new mbanative dll of WixToolset.Mba.Core.
Sean Hall committed
Dec 22, 2019 at 10:31 UTC
24379873f589cff33965f1104041f61c0c4503e0
20 files changed
+402
-24
balutil.sln
+21
-2
@@ -1,12 +1,16 @@
1
2
Microsoft Visual Studio Solution File, Format Version 12.00
3
-# Visual Studio 15
4
-VisualStudioVersion = 15.0.26730.12
3
+# Visual Studio Version 16
4
+VisualStudioVersion = 16.0.29503.13
5
MinimumVisualStudioVersion = 15.0.26124.0
6
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "balutil", "src\balutil\balutil.vcxproj", "{EDCB8095-0E6A-43E0-BC33-C4F762FC5CDB}"
7
EndProject
8
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WixToolset.Mba.Core", "src\WixToolset.Mba.Core\WixToolset.Mba.Core.csproj", "{E7E1841E-A58E-4901-B9CA-4845B807D45F}"
9
EndProject
10
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mbanative", "src\mbanative\mbanative.vcxproj", "{665E0441-17F9-4105-B202-EDF274657F6E}"
11
+EndProject
12
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolsetTest.Mba.Core", "src\test\WixToolsetTest.Mba.Core\WixToolsetTest.Mba.Core.csproj", "{F54997F7-10D7-409B-B9F2-DB546490EDC0}"
13
+EndProject
14
Global
15
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16
Debug|x64 = Debug|x64
@@ -31,6 +35,21 @@ Global
35
{E7E1841E-A58E-4901-B9CA-4845B807D45F}.Release|x64.Build.0 = Release|Any CPU
36
{E7E1841E-A58E-4901-B9CA-4845B807D45F}.Release|x86.ActiveCfg = Release|Any CPU
37
{E7E1841E-A58E-4901-B9CA-4845B807D45F}.Release|x86.Build.0 = Release|Any CPU
38
+ {665E0441-17F9-4105-B202-EDF274657F6E}.Debug|x64.ActiveCfg = Debug|x64
39
+ {665E0441-17F9-4105-B202-EDF274657F6E}.Debug|x64.Build.0 = Debug|x64
40
+ {665E0441-17F9-4105-B202-EDF274657F6E}.Debug|x86.ActiveCfg = Debug|Win32
41
+ {665E0441-17F9-4105-B202-EDF274657F6E}.Debug|x86.Build.0 = Debug|Win32
42
+ {665E0441-17F9-4105-B202-EDF274657F6E}.Release|x64.ActiveCfg = Release|Win32
43
+ {665E0441-17F9-4105-B202-EDF274657F6E}.Release|x86.ActiveCfg = Release|Win32
44
+ {665E0441-17F9-4105-B202-EDF274657F6E}.Release|x86.Build.0 = Release|Win32
45
+ {F54997F7-10D7-409B-B9F2-DB546490EDC0}.Debug|x64.ActiveCfg = Debug|x64
46
+ {F54997F7-10D7-409B-B9F2-DB546490EDC0}.Debug|x64.Build.0 = Debug|x64
47
+ {F54997F7-10D7-409B-B9F2-DB546490EDC0}.Debug|x86.ActiveCfg = Debug|x86
48
+ {F54997F7-10D7-409B-B9F2-DB546490EDC0}.Debug|x86.Build.0 = Debug|x86
49
+ {F54997F7-10D7-409B-B9F2-DB546490EDC0}.Release|x64.ActiveCfg = Release|Any CPU
50
+ {F54997F7-10D7-409B-B9F2-DB546490EDC0}.Release|x64.Build.0 = Release|Any CPU
51
+ {F54997F7-10D7-409B-B9F2-DB546490EDC0}.Release|x86.ActiveCfg = Release|Any CPU
52
+ {F54997F7-10D7-409B-B9F2-DB546490EDC0}.Release|x86.Build.0 = Release|Any CPU
53
EndGlobalSection
54
GlobalSection(SolutionProperties) = preSolution
55
HideSolutionNode = FALSE
src/WixToolset.Mba.Core/BalUtil.cs
new
+22
@@ -0,0 +1,22 @@
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+namespace WixToolset.Mba.Core
4
+{
5
+ using System;
6
+ using System.Runtime.InteropServices;
7
+
8
+ internal static class BalUtil
9
+ {
10
+ [DllImport("mbanative.dll", ExactSpelling = true, PreserveSig = false)]
11
+ internal static extern IBootstrapperEngine InitializeFromCreateArgs(
12
+ IntPtr pArgs,
13
+ ref Command pCommand
14
+ );
15
+
16
+ [DllImport("mbanative.dll", ExactSpelling = true)]
17
+ internal static extern void StoreBAInCreateResults(
18
+ IntPtr pResults,
19
+ [MarshalAs(UnmanagedType.Interface)] IBootstrapperApplication pBA
20
+ );
21
+ }
22
+}
src/WixToolset.Mba.Core/BaseBootstrapperApplicationFactory.cs
+24
-4
@@ -2,15 +2,35 @@
2
3
namespace WixToolset.Mba.Core
4
{
5
+ using System;
6
+ using System.Runtime.InteropServices;
7
+
8
public abstract class BaseBootstrapperApplicationFactory : IBootstrapperApplicationFactory
9
{
7
- public IBootstrapperApplication Create(IBootstrapperEngine pEngine, ref Command command)
10
+ public void Create(IntPtr pArgs, IntPtr pResults)
11
{
9
- IEngine engine = new Engine(pEngine);
10
- IBootstrapperCommand bootstrapperCommand = command.GetBootstrapperCommand();
11
- return this.Create(engine, bootstrapperCommand);
12
+ InitializeFromCreateArgs(pArgs, out var engine, out var bootstrapperCommand);
13
+
14
+ var ba = this.Create(engine, bootstrapperCommand);
15
+ StoreBAInCreateResults(pResults, ba);
16
}
17
18
protected abstract IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand);
19
+
20
+ public static void InitializeFromCreateArgs(IntPtr pArgs, out IEngine engine, out IBootstrapperCommand bootstrapperCommand)
21
+ {
22
+ Command pCommand = new Command
23
+ {
24
+ cbSize = Marshal.SizeOf(typeof(Command))
25
+ };
26
+ var pEngine = BalUtil.InitializeFromCreateArgs(pArgs, ref pCommand);
27
+ engine = new Engine(pEngine);
28
+ bootstrapperCommand = pCommand.GetBootstrapperCommand();
29
+ }
30
+
31
+ public static void StoreBAInCreateResults(IntPtr pResults, IBootstrapperApplication ba)
32
+ {
33
+ BalUtil.StoreBAInCreateResults(pResults, ba);
34
+ }
35
}
36
}
src/WixToolset.Mba.Core/BootstrapperApplicationFactory.cs
+6
-8
@@ -8,7 +8,7 @@ namespace WixToolset.Mba.Core
8
using System.Runtime.InteropServices;
9
10
/// <summary>
11
- /// Entry point for the MBA host to create and return the IBootstrapperApplication implementation to the engine.
11
+ /// Entry point for the MBA host to create and return the BA to the engine.
12
/// </summary>
13
[ClassInterface(ClassInterfaceType.None)]
14
public sealed class BootstrapperApplicationFactory : MarshalByRefObject, IBootstrapperApplicationFactory
@@ -21,14 +21,13 @@ namespace WixToolset.Mba.Core
21
}
22
23
/// <summary>
24
- /// Loads the bootstrapper application assembly and creates an instance of the IBootstrapperApplication.
24
+ /// Loads the bootstrapper application assembly and calls its IBootstrapperApplicationFactory.Create method.
25
/// </summary>
26
- /// <param name="pEngine">IBootstrapperEngine provided for the bootstrapper application.</param>
27
- /// <param name="command">Command line for the bootstrapper application.</param>
28
- /// <returns>Bootstrapper application via <see cref="IBootstrapperApplication"/> interface.</returns>
26
+ /// <param name="pArgs">Pointer to BOOTSTRAPPER_CREATE_ARGS struct.</param>
27
+ /// <param name="pResults">Pointer to BOOTSTRAPPER_CREATE_RESULTS struct.</param>
28
/// <exception cref="MissingAttributeException">The bootstrapper application assembly
29
/// does not define the <see cref="BootstrapperApplicationFactoryAttribute"/>.</exception>
31
- public IBootstrapperApplication Create(IBootstrapperEngine pEngine, ref Command command)
30
+ public void Create(IntPtr pArgs, IntPtr pResults)
31
{
32
// Get the wix.boostrapper section group to get the name of the bootstrapper application assembly to host.
33
var section = ConfigurationManager.GetSection("wix.bootstrapper/host") as HostSection;
@@ -45,8 +44,7 @@ namespace WixToolset.Mba.Core
44
throw new InvalidBootstrapperApplicationFactoryException();
45
}
46
48
- var ba = baFactory.Create(pEngine, ref command);
49
- return ba;
47
+ baFactory.Create(pArgs, pResults);
48
}
49
50
/// <summary>
src/WixToolset.Mba.Core/IBootstrapperApplicationFactory.cs
+25
-3
@@ -12,9 +12,9 @@ namespace WixToolset.Mba.Core
12
[GeneratedCodeAttribute("WixToolset.Bootstrapper.InteropCodeGenerator", "1.0.0.0")]
13
public interface IBootstrapperApplicationFactory
14
{
15
- IBootstrapperApplication Create(
16
- [MarshalAs(UnmanagedType.Interface)] IBootstrapperEngine pEngine,
17
- ref Command command
15
+ void Create(
16
+ IntPtr pArgs,
17
+ IntPtr pResults
18
);
19
}
20
@@ -23,6 +23,7 @@ namespace WixToolset.Mba.Core
23
[GeneratedCodeAttribute("WixToolset.Bootstrapper.InteropCodeGenerator", "1.0.0.0")]
24
public struct Command
25
{
26
+ [MarshalAs(UnmanagedType.I4)] internal int cbSize;
27
[MarshalAs(UnmanagedType.U4)] private readonly LaunchAction action;
28
[MarshalAs(UnmanagedType.U4)] private readonly Display display;
29
[MarshalAs(UnmanagedType.U4)] private readonly Restart restart;
@@ -49,4 +50,25 @@ namespace WixToolset.Mba.Core
50
this.wzLayoutDirectory);
51
}
52
}
53
+
54
+ [Serializable]
55
+ [StructLayout(LayoutKind.Sequential)]
56
+ [GeneratedCodeAttribute("WixToolset.Bootstrapper.InteropCodeGenerator", "1.0.0.0")]
57
+ public struct BootstrapperCreateArgs
58
+ {
59
+ [MarshalAs(UnmanagedType.I4)] public readonly int cbSize;
60
+ [MarshalAs(UnmanagedType.I8)] public readonly long qwEngineAPIVersion;
61
+ public readonly IntPtr pfnBootstrapperEngineProc;
62
+ public readonly IntPtr pvBootstrapperEngineProcContext;
63
+ public readonly IntPtr pCommand;
64
+
65
+ public BootstrapperCreateArgs(long version, IntPtr pEngineProc, IntPtr pEngineContext, IntPtr pCommand)
66
+ {
67
+ this.cbSize = Marshal.SizeOf(typeof(BootstrapperCreateArgs));
68
+ this.qwEngineAPIVersion = version;
69
+ this.pfnBootstrapperEngineProc = pEngineProc;
70
+ this.pvBootstrapperEngineProcContext = pEngineContext;
71
+ this.pCommand = pCommand;
72
+ }
73
+ }
74
}
src/WixToolset.Mba.Core/WixToolset.Mba.Core.csproj
+1
@@ -23,6 +23,7 @@
23
<DefineConstants>$(DefineConstants);TRACE</DefineConstants>
24
</PropertyGroup>
25
<ItemGroup>
26
+ <Compile Include="BalUtil.cs" />
27
<Compile Include="BaseBootstrapperApplicationFactory.cs" />
28
<Compile Include="BootstrapperApplication.cs" />
29
<Compile Include="BootstrapperApplicationData.cs" />
src/WixToolset.Mba.Core/WixToolset.Mba.Core.nuspec
+3
-1
@@ -7,7 +7,7 @@
7
<owners>WiX Toolset Team</owners>
8
<!-- <license type="expression">MS-RL</license> -->
9
<licenseUrl>https://licenses.nuget.org/MS-RL</licenseUrl>
10
- <projectUrl>https://github.com/wixtoolset/BootstrapperCore</projectUrl>
10
+ <projectUrl>https://github.com/wixtoolset/balutil</projectUrl>
11
<requireLicenseAcceptance>false</requireLicenseAcceptance>
12
<description>$description$</description>
13
<copyright>$copyright$</copyright>
@@ -15,6 +15,8 @@
15
16
<files>
17
<file src="..\..\build\$configuration$\$id$.config" target="samples" />
18
+ <file src="build\net20\$id$.props" target="build\net20" />
19
+ <file src="..\..\build\$configuration$\v141_xp\x86\mbanative.dll" target="build\net20\x86" />
20
<file src="..\..\build\$configuration$\$id$.h" target="build\native\include" />
21
<file src="..\..\build\$configuration$\$id$.dll" target="lib\net20" />
22
</files>
src/WixToolset.Mba.Core/build/net20/WixToolset.Mba.Core.props
new
+11
@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
+
4
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
5
+ <PropertyGroup>
6
+ <WixToolsetMbaNativePath Condition=" '$(WixToolsetMbaNativePath)' == '' ">$(MSBuildThisFileDirectory)x86\mbanative.dll</WixToolsetMbaNativePath>
7
+ </PropertyGroup>
8
+ <ItemGroup>
9
+ <Content Include="$(WixToolsetMbaNativePath)" CopyToOutputDirectory="Always" />
10
+ </ItemGroup>
11
+</Project>
src/balutil/balutil.vcxproj
+4
-2
@@ -2,7 +2,7 @@
2
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
4
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
5
- <Import Project="..\..\packages\WixToolset.BootstrapperCore.Native.4.0.8\build\WixToolset.BootstrapperCore.Native.props" Condition="Exists('..\..\packages\WixToolset.BootstrapperCore.Native.4.0.8\build\WixToolset.BootstrapperCore.Native.props')" />
5
+ <Import Project="..\..\packages\WixToolset.BootstrapperCore.Native.4.0.10\build\WixToolset.BootstrapperCore.Native.props" Condition="Exists('..\..\packages\WixToolset.BootstrapperCore.Native.4.0.10\build\WixToolset.BootstrapperCore.Native.props')" />
6
<Import Project="..\..\packages\WixToolset.DUtil.4.0.18\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.18\build\WixToolset.DUtil.props')" />
7
8
<ItemGroup Label="ProjectConfigurations">
@@ -70,7 +70,9 @@
70
<ClInclude Include="inc\balretry.h" />
71
<ClInclude Include="inc\balutil.h" />
72
<ClInclude Include="inc\IBAFunctions.h" />
73
+ <ClInclude Include="inc\IBootstrapperApplication.h" />
74
<ClInclude Include="inc\IBootstrapperApplicationFactory.h" />
75
+ <ClInclude Include="inc\IBootstrapperEngine.h" />
76
<ClInclude Include="precomp.h" />
77
</ItemGroup>
78
@@ -88,7 +90,7 @@
90
<PropertyGroup>
91
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
92
</PropertyGroup>
91
- <Error Condition="!Exists('..\..\packages\WixToolset.BootstrapperCore.Native.4.0.8\build\WixToolset.BootstrapperCore.Native.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.BootstrapperCore.Native.4.0.8\build\WixToolset.BootstrapperCore.Native.props'))" />
93
+ <Error Condition="!Exists('..\..\packages\WixToolset.BootstrapperCore.Native.4.0.10\build\WixToolset.BootstrapperCore.Native.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.BootstrapperCore.Native.4.0.10\build\WixToolset.BootstrapperCore.Native.props'))" />
94
<Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.18\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.18\build\WixToolset.DUtil.props'))" />
95
<Error Condition="!Exists('..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets'))" />
96
</Target>
src/balutil/inc/IBootstrapperApplicationFactory.h
+2
-3
@@ -7,8 +7,7 @@
7
DECLARE_INTERFACE_IID_(IBootstrapperApplicationFactory, IUnknown, "2965A12F-AC7B-43A0-85DF-E4B2168478A4")
8
{
9
STDMETHOD(Create)(
10
- __in IBootstrapperEngine* pEngine,
11
- __in const BOOTSTRAPPER_COMMAND *pCommand,
12
- __out IBootstrapperApplication **ppApplication
10
+ __in const BOOTSTRAPPER_CREATE_ARGS* pArgs,
11
+ __inout BOOTSTRAPPER_CREATE_RESULTS *pResults
12
);
13
};
src/balutil/packages.config
+1
-1
@@ -1,6 +1,6 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<packages>
3
<package id="Nerdbank.GitVersioning" version="2.1.65" targetFramework="native" developmentDependency="true" />
4
- <package id="WixToolset.BootstrapperCore.Native" version="4.0.8" targetFramework="native" />
4
+ <package id="WixToolset.BootstrapperCore.Native" version="4.0.10" targetFramework="native" />
5
<package id="WixToolset.DUtil" version="4.0.18" targetFramework="native" />
6
</packages>
\ No newline at end of file
src/mbanative/mbanative.cpp
new
+29
@@ -0,0 +1,29 @@
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+#include "precomp.h"
4
+#include "BalBaseBootstrapperApplicationProc.h"
5
+
6
+extern "C" HRESULT WINAPI InitializeFromCreateArgs(
7
+ __in const BOOTSTRAPPER_CREATE_ARGS* pArgs,
8
+ __inout BOOTSTRAPPER_COMMAND* pCommand,
9
+ __out IBootstrapperEngine** ppEngine
10
+ )
11
+{
12
+ HRESULT hr = S_OK;
13
+
14
+ hr = BalInitializeFromCreateArgs(pArgs, ppEngine);
15
+ ExitOnFailure(hr, "Failed to initialize Bal.");
16
+
17
+ memcpy_s(pCommand, pCommand->cbSize, pArgs->pCommand, pArgs->pCommand->cbSize);
18
+LExit:
19
+ return hr;
20
+}
21
+
22
+extern "C" void WINAPI StoreBAInCreateResults(
23
+ __inout BOOTSTRAPPER_CREATE_RESULTS* pResults,
24
+ __in IBootstrapperApplication* pBA
25
+ )
26
+{
27
+ pResults->pfnBootstrapperApplicationProc = BalBaseBootstrapperApplicationProc;
28
+ pResults->pvBootstrapperApplicationProcContext = pBA;
29
+}
src/mbanative/mbanative.def
new
+6
@@ -0,0 +1,6 @@
1
+; Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+
4
+EXPORTS
5
+ InitializeFromCreateArgs
6
+ StoreBAInCreateResults
src/mbanative/mbanative.vcxproj
new
+76
@@ -0,0 +1,76 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
+
4
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
5
+ <Import Project="..\..\packages\WixToolset.BootstrapperCore.Native.4.0.10\build\WixToolset.BootstrapperCore.Native.props" Condition="Exists('..\..\packages\WixToolset.BootstrapperCore.Native.4.0.10\build\WixToolset.BootstrapperCore.Native.props')" />
6
+ <Import Project="..\..\packages\WixToolset.DUtil.4.0.18\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.18\build\WixToolset.DUtil.props')" />
7
+
8
+ <ItemGroup Label="ProjectConfigurations">
9
+ <ProjectConfiguration Include="Debug|Win32">
10
+ <Configuration>Debug</Configuration>
11
+ <Platform>Win32</Platform>
12
+ </ProjectConfiguration>
13
+ <ProjectConfiguration Include="Release|Win32">
14
+ <Configuration>Release</Configuration>
15
+ <Platform>Win32</Platform>
16
+ </ProjectConfiguration>
17
+ <ProjectConfiguration Include="Debug|x64">
18
+ <Configuration>Debug</Configuration>
19
+ <Platform>x64</Platform>
20
+ </ProjectConfiguration>
21
+ <ProjectConfiguration Include="Release|x64">
22
+ <Configuration>Release</Configuration>
23
+ <Platform>x64</Platform>
24
+ </ProjectConfiguration>
25
+ </ItemGroup>
26
+
27
+ <PropertyGroup Label="Globals">
28
+ <ProjectGuid>{665E0441-17F9-4105-B202-EDF274657F6E}</ProjectGuid>
29
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
30
+ <PlatformToolset>v141</PlatformToolset>
31
+ <CharacterSet>Unicode</CharacterSet>
32
+ <TargetName>mbanative</TargetName>
33
+ <ProjectModuleDefinitionFile>mbanative.def</ProjectModuleDefinitionFile>
34
+ </PropertyGroup>
35
+
36
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
37
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
38
+ <Import Project="..\NativeMultiTargeting.Build.props" />
39
+
40
+ <PropertyGroup>
41
+ <ProjectAdditionalIncludeDirectories>..\balutil\inc</ProjectAdditionalIncludeDirectories>
42
+ <ProjectAdditionalLinkLibraries>balutil.lib</ProjectAdditionalLinkLibraries>
43
+ </PropertyGroup>
44
+
45
+ <ItemGroup>
46
+ <ClCompile Include="mbanative.cpp" />
47
+ <ClCompile Include="precomp.cpp">
48
+ <PrecompiledHeader>Create</PrecompiledHeader>
49
+ </ClCompile>
50
+ </ItemGroup>
51
+ <ItemGroup>
52
+ <ClInclude Include="precomp.h" />
53
+ </ItemGroup>
54
+ <ItemGroup>
55
+ <None Include="mbanative.def" />
56
+ </ItemGroup>
57
+
58
+ <ItemGroup>
59
+ <None Include="packages.config" />
60
+ </ItemGroup>
61
+
62
+ <ItemGroup>
63
+ <ProjectReference Include="..\balutil\balutil.vcxproj" />
64
+ </ItemGroup>
65
+
66
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
67
+ <Import Project="..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets')" />
68
+ <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
69
+ <PropertyGroup>
70
+ <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
71
+ </PropertyGroup>
72
+ <Error Condition="!Exists('..\..\packages\WixToolset.BootstrapperCore.Native.4.0.10\build\WixToolset.BootstrapperCore.Native.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.BootstrapperCore.Native.4.0.10\build\WixToolset.BootstrapperCore.Native.props'))" />
73
+ <Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.18\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.18\build\WixToolset.DUtil.props'))" />
74
+ <Error Condition="!Exists('..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets'))" />
75
+ </Target>
76
+</Project>
src/mbanative/packages.config
new
+6
@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<packages>
3
+ <package id="Nerdbank.GitVersioning" version="2.1.65" targetFramework="native" developmentDependency="true" />
4
+ <package id="WixToolset.BootstrapperCore.Native" version="4.0.10" targetFramework="native" />
5
+ <package id="WixToolset.DUtil" version="4.0.18" targetFramework="native" />
6
+</packages>
\ No newline at end of file
src/mbanative/precomp.cpp
new
+3
@@ -0,0 +1,3 @@
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+#include "precomp.h"
src/mbanative/precomp.h
new
+15
@@ -0,0 +1,15 @@
1
+#pragma once
2
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
3
+
4
+
5
+#include <windows.h>
6
+#include <msiquery.h>
7
+
8
+#include <dutil.h>
9
+
10
+#include "BootstrapperEngine.h"
11
+#include "BootstrapperApplication.h"
12
+#include "IBootstrapperEngine.h"
13
+#include "IBootstrapperApplication.h"
14
+
15
+#include "balutil.h"
src/test/WixToolsetTest.Mba.Core/BaseBootstrapperApplicationFactoryFixture.cs
new
+113
@@ -0,0 +1,113 @@
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+namespace WixToolsetTest.Util
4
+{
5
+ using System;
6
+ using System.Runtime.InteropServices;
7
+ using WixToolset.Mba.Core;
8
+ using Xunit;
9
+
10
+ public class BaseBootstrapperApplicationFactoryFixture
11
+ {
12
+ [Fact]
13
+ public void CanCreateBA()
14
+ {
15
+ var command = new TestCommand
16
+ {
17
+ action = LaunchAction.Install,
18
+ cbSize = Marshal.SizeOf(typeof(TestCommand)),
19
+ display = Display.Full,
20
+ wzCommandLine = "this \"is a\" test",
21
+ };
22
+ var pCommand = Marshal.AllocHGlobal(command.cbSize);
23
+ try
24
+ {
25
+ Marshal.StructureToPtr(command, pCommand, false);
26
+ var createArgs = new BootstrapperCreateArgs(0, IntPtr.Zero, IntPtr.Zero, pCommand);
27
+ var pArgs = Marshal.AllocHGlobal(createArgs.cbSize);
28
+ try
29
+ {
30
+ Marshal.StructureToPtr(createArgs, pArgs, false);
31
+ var createResults = new TestCreateResults
32
+ {
33
+ cbSize = Marshal.SizeOf<TestCreateResults>(),
34
+ };
35
+ var pResults = Marshal.AllocHGlobal(createResults.cbSize);
36
+ try
37
+ {
38
+ var baFactory = new TestBAFactory();
39
+ baFactory.Create(pArgs, pResults);
40
+
41
+ createResults = Marshal.PtrToStructure<TestCreateResults>(pResults);
42
+ Assert.Equal(baFactory.BA, createResults.pBA);
43
+ Assert.Equal(baFactory.BA.Command.Action, command.action);
44
+ Assert.Equal(baFactory.BA.Command.Display, command.display);
45
+ Assert.Equal(baFactory.BA.Command.CommandLineArgs, new string[] { "this", "is a", "test" });
46
+ }
47
+ finally
48
+ {
49
+ Marshal.FreeHGlobal(pResults);
50
+ }
51
+ }
52
+ finally
53
+ {
54
+ Marshal.FreeHGlobal(pArgs);
55
+ }
56
+ }
57
+ finally
58
+ {
59
+ Marshal.FreeHGlobal(pCommand);
60
+ }
61
+ }
62
+
63
+ internal class TestBAFactory : BaseBootstrapperApplicationFactory
64
+ {
65
+ public TestBA BA { get; private set; }
66
+
67
+ protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand)
68
+ {
69
+ this.BA = new TestBA(engine, bootstrapperCommand);
70
+ return this.BA;
71
+ }
72
+ }
73
+
74
+ internal class TestBA : BootstrapperApplication
75
+ {
76
+ public IBootstrapperCommand Command { get; }
77
+
78
+ public TestBA(IEngine engine, IBootstrapperCommand command)
79
+ : base(engine)
80
+ {
81
+ this.Command = command;
82
+ }
83
+
84
+ protected override void Run()
85
+ {
86
+ }
87
+ }
88
+
89
+ [StructLayout(LayoutKind.Sequential)]
90
+ public struct TestCommand
91
+ {
92
+ public int cbSize;
93
+ public LaunchAction action;
94
+ public Display display;
95
+ public Restart restart;
96
+ [MarshalAs(UnmanagedType.LPWStr)] public string wzCommandLine;
97
+ public int nCmdShow;
98
+ public ResumeType resume;
99
+ public IntPtr hwndSplashScreen;
100
+ public RelationType relation;
101
+ [MarshalAs(UnmanagedType.Bool)] public bool passthrough;
102
+ [MarshalAs(UnmanagedType.LPWStr)] public string wzLayoutDirectory;
103
+ }
104
+
105
+ [StructLayout(LayoutKind.Sequential)]
106
+ public struct TestCreateResults
107
+ {
108
+ public int cbSize;
109
+ public IntPtr pBAProc;
110
+ [MarshalAs(UnmanagedType.Interface)] public IBootstrapperApplication pBA;
111
+ }
112
+ }
113
+}
src/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.csproj
new
+29
@@ -0,0 +1,29 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
+
4
+<Project Sdk="Microsoft.NET.Sdk">
5
+ <PropertyGroup>
6
+ <TargetFramework>netcoreapp2.1</TargetFramework>
7
+ <IsPackable>false</IsPackable>
8
+ <Platforms>AnyCPU;x86;x64</Platforms>
9
+ </PropertyGroup>
10
+
11
+ <PropertyGroup>
12
+ <NoWarn>NU1701</NoWarn>
13
+ </PropertyGroup>
14
+
15
+ <ItemGroup>
16
+ <ProjectReference Include="..\..\mbanative\mbanative.vcxproj">
17
+ <Project>{665E0441-17F9-4105-B202-EDF274657F6E}</Project>
18
+ <OutputItemType>Content</OutputItemType>
19
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
20
+ </ProjectReference>
21
+ <ProjectReference Include="..\..\WixToolset.Mba.Core\WixToolset.Mba.Core.csproj" />
22
+ </ItemGroup>
23
+
24
+ <ItemGroup>
25
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
26
+ <PackageReference Include="xunit" Version="2.4.1" />
27
+ <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="All" />
28
+ </ItemGroup>
29
+</Project>
src/test/WixToolsetTest.Mba.Core/WixToolsetTest.Mba.Core.v3.ncrunchproject
new
+5
@@ -0,0 +1,5 @@
1
+<ProjectConfiguration>
2
+ <Settings>
3
+ <CopyReferencedAssembliesToWorkspace>True</CopyReferencedAssembliesToWorkspace>
4
+ </Settings>
5
+</ProjectConfiguration>
\ No newline at end of file