Move the responsibility of wrapping the binary interfaces from mbahost to the new mbanative dll of WixToolset.Mba.Core.

This commit is contained in:
Sean Hall 2019-12-22 10:31:33 +11:00
Родитель f3c383c241
Коммит 24379873f5
20 изменённых файлов: 402 добавлений и 24 удалений

Просмотреть файл

@ -1,12 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
# Visual Studio Version 16
VisualStudioVersion = 16.0.29503.13
MinimumVisualStudioVersion = 15.0.26124.0
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "balutil", "src\balutil\balutil.vcxproj", "{EDCB8095-0E6A-43E0-BC33-C4F762FC5CDB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WixToolset.Mba.Core", "src\WixToolset.Mba.Core\WixToolset.Mba.Core.csproj", "{E7E1841E-A58E-4901-B9CA-4845B807D45F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mbanative", "src\mbanative\mbanative.vcxproj", "{665E0441-17F9-4105-B202-EDF274657F6E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolsetTest.Mba.Core", "src\test\WixToolsetTest.Mba.Core\WixToolsetTest.Mba.Core.csproj", "{F54997F7-10D7-409B-B9F2-DB546490EDC0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@ -31,6 +35,21 @@ Global
{E7E1841E-A58E-4901-B9CA-4845B807D45F}.Release|x64.Build.0 = Release|Any CPU
{E7E1841E-A58E-4901-B9CA-4845B807D45F}.Release|x86.ActiveCfg = Release|Any CPU
{E7E1841E-A58E-4901-B9CA-4845B807D45F}.Release|x86.Build.0 = Release|Any CPU
{665E0441-17F9-4105-B202-EDF274657F6E}.Debug|x64.ActiveCfg = Debug|x64
{665E0441-17F9-4105-B202-EDF274657F6E}.Debug|x64.Build.0 = Debug|x64
{665E0441-17F9-4105-B202-EDF274657F6E}.Debug|x86.ActiveCfg = Debug|Win32
{665E0441-17F9-4105-B202-EDF274657F6E}.Debug|x86.Build.0 = Debug|Win32
{665E0441-17F9-4105-B202-EDF274657F6E}.Release|x64.ActiveCfg = Release|Win32
{665E0441-17F9-4105-B202-EDF274657F6E}.Release|x86.ActiveCfg = Release|Win32
{665E0441-17F9-4105-B202-EDF274657F6E}.Release|x86.Build.0 = Release|Win32
{F54997F7-10D7-409B-B9F2-DB546490EDC0}.Debug|x64.ActiveCfg = Debug|x64
{F54997F7-10D7-409B-B9F2-DB546490EDC0}.Debug|x64.Build.0 = Debug|x64
{F54997F7-10D7-409B-B9F2-DB546490EDC0}.Debug|x86.ActiveCfg = Debug|x86
{F54997F7-10D7-409B-B9F2-DB546490EDC0}.Debug|x86.Build.0 = Debug|x86
{F54997F7-10D7-409B-B9F2-DB546490EDC0}.Release|x64.ActiveCfg = Release|Any CPU
{F54997F7-10D7-409B-B9F2-DB546490EDC0}.Release|x64.Build.0 = Release|Any CPU
{F54997F7-10D7-409B-B9F2-DB546490EDC0}.Release|x86.ActiveCfg = Release|Any CPU
{F54997F7-10D7-409B-B9F2-DB546490EDC0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Просмотреть файл

@ -0,0 +1,22 @@
// 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.
namespace WixToolset.Mba.Core
{
using System;
using System.Runtime.InteropServices;
internal static class BalUtil
{
[DllImport("mbanative.dll", ExactSpelling = true, PreserveSig = false)]
internal static extern IBootstrapperEngine InitializeFromCreateArgs(
IntPtr pArgs,
ref Command pCommand
);
[DllImport("mbanative.dll", ExactSpelling = true)]
internal static extern void StoreBAInCreateResults(
IntPtr pResults,
[MarshalAs(UnmanagedType.Interface)] IBootstrapperApplication pBA
);
}
}

Просмотреть файл

@ -2,15 +2,35 @@
namespace WixToolset.Mba.Core
{
using System;
using System.Runtime.InteropServices;
public abstract class BaseBootstrapperApplicationFactory : IBootstrapperApplicationFactory
{
public IBootstrapperApplication Create(IBootstrapperEngine pEngine, ref Command command)
public void Create(IntPtr pArgs, IntPtr pResults)
{
IEngine engine = new Engine(pEngine);
IBootstrapperCommand bootstrapperCommand = command.GetBootstrapperCommand();
return this.Create(engine, bootstrapperCommand);
InitializeFromCreateArgs(pArgs, out var engine, out var bootstrapperCommand);
var ba = this.Create(engine, bootstrapperCommand);
StoreBAInCreateResults(pResults, ba);
}
protected abstract IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand);
public static void InitializeFromCreateArgs(IntPtr pArgs, out IEngine engine, out IBootstrapperCommand bootstrapperCommand)
{
Command pCommand = new Command
{
cbSize = Marshal.SizeOf(typeof(Command))
};
var pEngine = BalUtil.InitializeFromCreateArgs(pArgs, ref pCommand);
engine = new Engine(pEngine);
bootstrapperCommand = pCommand.GetBootstrapperCommand();
}
public static void StoreBAInCreateResults(IntPtr pResults, IBootstrapperApplication ba)
{
BalUtil.StoreBAInCreateResults(pResults, ba);
}
}
}

Просмотреть файл

@ -8,7 +8,7 @@ namespace WixToolset.Mba.Core
using System.Runtime.InteropServices;
/// <summary>
/// Entry point for the MBA host to create and return the IBootstrapperApplication implementation to the engine.
/// Entry point for the MBA host to create and return the BA to the engine.
/// </summary>
[ClassInterface(ClassInterfaceType.None)]
public sealed class BootstrapperApplicationFactory : MarshalByRefObject, IBootstrapperApplicationFactory
@ -21,14 +21,13 @@ namespace WixToolset.Mba.Core
}
/// <summary>
/// Loads the bootstrapper application assembly and creates an instance of the IBootstrapperApplication.
/// Loads the bootstrapper application assembly and calls its IBootstrapperApplicationFactory.Create method.
/// </summary>
/// <param name="pEngine">IBootstrapperEngine provided for the bootstrapper application.</param>
/// <param name="command">Command line for the bootstrapper application.</param>
/// <returns>Bootstrapper application via <see cref="IBootstrapperApplication"/> interface.</returns>
/// <param name="pArgs">Pointer to BOOTSTRAPPER_CREATE_ARGS struct.</param>
/// <param name="pResults">Pointer to BOOTSTRAPPER_CREATE_RESULTS struct.</param>
/// <exception cref="MissingAttributeException">The bootstrapper application assembly
/// does not define the <see cref="BootstrapperApplicationFactoryAttribute"/>.</exception>
public IBootstrapperApplication Create(IBootstrapperEngine pEngine, ref Command command)
public void Create(IntPtr pArgs, IntPtr pResults)
{
// Get the wix.boostrapper section group to get the name of the bootstrapper application assembly to host.
var section = ConfigurationManager.GetSection("wix.bootstrapper/host") as HostSection;
@ -45,8 +44,7 @@ namespace WixToolset.Mba.Core
throw new InvalidBootstrapperApplicationFactoryException();
}
var ba = baFactory.Create(pEngine, ref command);
return ba;
baFactory.Create(pArgs, pResults);
}
/// <summary>

Просмотреть файл

@ -12,9 +12,9 @@ namespace WixToolset.Mba.Core
[GeneratedCodeAttribute("WixToolset.Bootstrapper.InteropCodeGenerator", "1.0.0.0")]
public interface IBootstrapperApplicationFactory
{
IBootstrapperApplication Create(
[MarshalAs(UnmanagedType.Interface)] IBootstrapperEngine pEngine,
ref Command command
void Create(
IntPtr pArgs,
IntPtr pResults
);
}
@ -23,6 +23,7 @@ namespace WixToolset.Mba.Core
[GeneratedCodeAttribute("WixToolset.Bootstrapper.InteropCodeGenerator", "1.0.0.0")]
public struct Command
{
[MarshalAs(UnmanagedType.I4)] internal int cbSize;
[MarshalAs(UnmanagedType.U4)] private readonly LaunchAction action;
[MarshalAs(UnmanagedType.U4)] private readonly Display display;
[MarshalAs(UnmanagedType.U4)] private readonly Restart restart;
@ -49,4 +50,25 @@ namespace WixToolset.Mba.Core
this.wzLayoutDirectory);
}
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
[GeneratedCodeAttribute("WixToolset.Bootstrapper.InteropCodeGenerator", "1.0.0.0")]
public struct BootstrapperCreateArgs
{
[MarshalAs(UnmanagedType.I4)] public readonly int cbSize;
[MarshalAs(UnmanagedType.I8)] public readonly long qwEngineAPIVersion;
public readonly IntPtr pfnBootstrapperEngineProc;
public readonly IntPtr pvBootstrapperEngineProcContext;
public readonly IntPtr pCommand;
public BootstrapperCreateArgs(long version, IntPtr pEngineProc, IntPtr pEngineContext, IntPtr pCommand)
{
this.cbSize = Marshal.SizeOf(typeof(BootstrapperCreateArgs));
this.qwEngineAPIVersion = version;
this.pfnBootstrapperEngineProc = pEngineProc;
this.pvBootstrapperEngineProcContext = pEngineContext;
this.pCommand = pCommand;
}
}
}

Просмотреть файл

@ -23,6 +23,7 @@
<DefineConstants>$(DefineConstants);TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="BalUtil.cs" />
<Compile Include="BaseBootstrapperApplicationFactory.cs" />
<Compile Include="BootstrapperApplication.cs" />
<Compile Include="BootstrapperApplicationData.cs" />

Просмотреть файл

@ -7,7 +7,7 @@
<owners>WiX Toolset Team</owners>
<!-- <license type="expression">MS-RL</license> -->
<licenseUrl>https://licenses.nuget.org/MS-RL</licenseUrl>
<projectUrl>https://github.com/wixtoolset/BootstrapperCore</projectUrl>
<projectUrl>https://github.com/wixtoolset/balutil</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<copyright>$copyright$</copyright>
@ -15,6 +15,8 @@
<files>
<file src="..\..\build\$configuration$\$id$.config" target="samples" />
<file src="build\net20\$id$.props" target="build\net20" />
<file src="..\..\build\$configuration$\v141_xp\x86\mbanative.dll" target="build\net20\x86" />
<file src="..\..\build\$configuration$\$id$.h" target="build\native\include" />
<file src="..\..\build\$configuration$\$id$.dll" target="lib\net20" />
</files>

Просмотреть файл

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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. -->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WixToolsetMbaNativePath Condition=" '$(WixToolsetMbaNativePath)' == '' ">$(MSBuildThisFileDirectory)x86\mbanative.dll</WixToolsetMbaNativePath>
</PropertyGroup>
<ItemGroup>
<Content Include="$(WixToolsetMbaNativePath)" CopyToOutputDirectory="Always" />
</ItemGroup>
</Project>

Просмотреть файл

@ -2,7 +2,7 @@
<!-- 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. -->
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<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')" />
<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')" />
<Import Project="..\..\packages\WixToolset.DUtil.4.0.18\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.18\build\WixToolset.DUtil.props')" />
<ItemGroup Label="ProjectConfigurations">
@ -70,7 +70,9 @@
<ClInclude Include="inc\balretry.h" />
<ClInclude Include="inc\balutil.h" />
<ClInclude Include="inc\IBAFunctions.h" />
<ClInclude Include="inc\IBootstrapperApplication.h" />
<ClInclude Include="inc\IBootstrapperApplicationFactory.h" />
<ClInclude Include="inc\IBootstrapperEngine.h" />
<ClInclude Include="precomp.h" />
</ItemGroup>
@ -88,7 +90,7 @@
<PropertyGroup>
<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>
</PropertyGroup>
<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'))" />
<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'))" />
<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'))" />
<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'))" />
</Target>

Просмотреть файл

@ -7,8 +7,7 @@
DECLARE_INTERFACE_IID_(IBootstrapperApplicationFactory, IUnknown, "2965A12F-AC7B-43A0-85DF-E4B2168478A4")
{
STDMETHOD(Create)(
__in IBootstrapperEngine* pEngine,
__in const BOOTSTRAPPER_COMMAND *pCommand,
__out IBootstrapperApplication **ppApplication
__in const BOOTSTRAPPER_CREATE_ARGS* pArgs,
__inout BOOTSTRAPPER_CREATE_RESULTS *pResults
);
};

Просмотреть файл

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Nerdbank.GitVersioning" version="2.1.65" targetFramework="native" developmentDependency="true" />
<package id="WixToolset.BootstrapperCore.Native" version="4.0.8" targetFramework="native" />
<package id="WixToolset.BootstrapperCore.Native" version="4.0.10" targetFramework="native" />
<package id="WixToolset.DUtil" version="4.0.18" targetFramework="native" />
</packages>

Просмотреть файл

@ -0,0 +1,29 @@
// 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.
#include "precomp.h"
#include "BalBaseBootstrapperApplicationProc.h"
extern "C" HRESULT WINAPI InitializeFromCreateArgs(
__in const BOOTSTRAPPER_CREATE_ARGS* pArgs,
__inout BOOTSTRAPPER_COMMAND* pCommand,
__out IBootstrapperEngine** ppEngine
)
{
HRESULT hr = S_OK;
hr = BalInitializeFromCreateArgs(pArgs, ppEngine);
ExitOnFailure(hr, "Failed to initialize Bal.");
memcpy_s(pCommand, pCommand->cbSize, pArgs->pCommand, pArgs->pCommand->cbSize);
LExit:
return hr;
}
extern "C" void WINAPI StoreBAInCreateResults(
__inout BOOTSTRAPPER_CREATE_RESULTS* pResults,
__in IBootstrapperApplication* pBA
)
{
pResults->pfnBootstrapperApplicationProc = BalBaseBootstrapperApplicationProc;
pResults->pvBootstrapperApplicationProcContext = pBA;
}

Просмотреть файл

@ -0,0 +1,6 @@
; 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.
EXPORTS
InitializeFromCreateArgs
StoreBAInCreateResults

Просмотреть файл

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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. -->
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<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')" />
<Import Project="..\..\packages\WixToolset.DUtil.4.0.18\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.18\build\WixToolset.DUtil.props')" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{665E0441-17F9-4105-B202-EDF274657F6E}</ProjectGuid>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<TargetName>mbanative</TargetName>
<ProjectModuleDefinitionFile>mbanative.def</ProjectModuleDefinitionFile>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="..\NativeMultiTargeting.Build.props" />
<PropertyGroup>
<ProjectAdditionalIncludeDirectories>..\balutil\inc</ProjectAdditionalIncludeDirectories>
<ProjectAdditionalLinkLibraries>balutil.lib</ProjectAdditionalLinkLibraries>
</PropertyGroup>
<ItemGroup>
<ClCompile Include="mbanative.cpp" />
<ClCompile Include="precomp.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="precomp.h" />
</ItemGroup>
<ItemGroup>
<None Include="mbanative.def" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\balutil\balutil.vcxproj" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<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>
</PropertyGroup>
<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'))" />
<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'))" />
<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'))" />
</Target>
</Project>

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Nerdbank.GitVersioning" version="2.1.65" targetFramework="native" developmentDependency="true" />
<package id="WixToolset.BootstrapperCore.Native" version="4.0.10" targetFramework="native" />
<package id="WixToolset.DUtil" version="4.0.18" targetFramework="native" />
</packages>

Просмотреть файл

@ -0,0 +1,3 @@
// 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.
#include "precomp.h"

15
src/mbanative/precomp.h Normal file
Просмотреть файл

@ -0,0 +1,15 @@
#pragma once
// 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.
#include <windows.h>
#include <msiquery.h>
#include <dutil.h>
#include "BootstrapperEngine.h"
#include "BootstrapperApplication.h"
#include "IBootstrapperEngine.h"
#include "IBootstrapperApplication.h"
#include "balutil.h"

Просмотреть файл

@ -0,0 +1,113 @@
// 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.
namespace WixToolsetTest.Util
{
using System;
using System.Runtime.InteropServices;
using WixToolset.Mba.Core;
using Xunit;
public class BaseBootstrapperApplicationFactoryFixture
{
[Fact]
public void CanCreateBA()
{
var command = new TestCommand
{
action = LaunchAction.Install,
cbSize = Marshal.SizeOf(typeof(TestCommand)),
display = Display.Full,
wzCommandLine = "this \"is a\" test",
};
var pCommand = Marshal.AllocHGlobal(command.cbSize);
try
{
Marshal.StructureToPtr(command, pCommand, false);
var createArgs = new BootstrapperCreateArgs(0, IntPtr.Zero, IntPtr.Zero, pCommand);
var pArgs = Marshal.AllocHGlobal(createArgs.cbSize);
try
{
Marshal.StructureToPtr(createArgs, pArgs, false);
var createResults = new TestCreateResults
{
cbSize = Marshal.SizeOf<TestCreateResults>(),
};
var pResults = Marshal.AllocHGlobal(createResults.cbSize);
try
{
var baFactory = new TestBAFactory();
baFactory.Create(pArgs, pResults);
createResults = Marshal.PtrToStructure<TestCreateResults>(pResults);
Assert.Equal(baFactory.BA, createResults.pBA);
Assert.Equal(baFactory.BA.Command.Action, command.action);
Assert.Equal(baFactory.BA.Command.Display, command.display);
Assert.Equal(baFactory.BA.Command.CommandLineArgs, new string[] { "this", "is a", "test" });
}
finally
{
Marshal.FreeHGlobal(pResults);
}
}
finally
{
Marshal.FreeHGlobal(pArgs);
}
}
finally
{
Marshal.FreeHGlobal(pCommand);
}
}
internal class TestBAFactory : BaseBootstrapperApplicationFactory
{
public TestBA BA { get; private set; }
protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand)
{
this.BA = new TestBA(engine, bootstrapperCommand);
return this.BA;
}
}
internal class TestBA : BootstrapperApplication
{
public IBootstrapperCommand Command { get; }
public TestBA(IEngine engine, IBootstrapperCommand command)
: base(engine)
{
this.Command = command;
}
protected override void Run()
{
}
}
[StructLayout(LayoutKind.Sequential)]
public struct TestCommand
{
public int cbSize;
public LaunchAction action;
public Display display;
public Restart restart;
[MarshalAs(UnmanagedType.LPWStr)] public string wzCommandLine;
public int nCmdShow;
public ResumeType resume;
public IntPtr hwndSplashScreen;
public RelationType relation;
[MarshalAs(UnmanagedType.Bool)] public bool passthrough;
[MarshalAs(UnmanagedType.LPWStr)] public string wzLayoutDirectory;
}
[StructLayout(LayoutKind.Sequential)]
public struct TestCreateResults
{
public int cbSize;
public IntPtr pBAProc;
[MarshalAs(UnmanagedType.Interface)] public IBootstrapperApplication pBA;
}
}
}

Просмотреть файл

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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. -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
<Platforms>AnyCPU;x86;x64</Platforms>
</PropertyGroup>
<PropertyGroup>
<NoWarn>NU1701</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\mbanative\mbanative.vcxproj">
<Project>{665E0441-17F9-4105-B202-EDF274657F6E}</Project>
<OutputItemType>Content</OutputItemType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</ProjectReference>
<ProjectReference Include="..\..\WixToolset.Mba.Core\WixToolset.Mba.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="All" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<CopyReferencedAssembliesToWorkspace>True</CopyReferencedAssembliesToWorkspace>
</Settings>
</ProjectConfiguration>