using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;
using System.Text;
-using System.Threading;
namespace Microsoft.NET.HostModel.AppHost
{
try
{
// Open the source host file.
- memoryMappedFile = MemoryMappedFile.CreateFromFile(appHostSourceFilePath, FileMode.Open, null, 0, MemoryMappedFileAccess.CopyOnWrite);
+ memoryMappedFile = MemoryMappedFile.CreateFromFile(appHostSourceFilePath, FileMode.Open, null, 0, MemoryMappedFileAccess.Read);
memoryMappedViewAccessor = memoryMappedFile.CreateViewAccessor(0, 0, MemoryMappedFileAccess.CopyOnWrite);
// Transform the host file in-memory.
int GetLastError() => Marshal.GetLastWin32Error();
}
+ [Fact]
+ public void CanCreateAppHost()
+ {
+ using (TestDirectory testDirectory = TestDirectory.Create())
+ {
+ string sourceAppHostMock = PrepareAppHostMockFile(testDirectory);
+ File.SetAttributes(sourceAppHostMock, FileAttributes.ReadOnly);
+ string destinationFilePath = Path.Combine(testDirectory.Path, "DestinationAppHost.exe.mock");
+ string appBinaryFilePath = "Test/App/Binary/Path.dll";
+ HostWriter.CreateAppHost(
+ sourceAppHostMock,
+ destinationFilePath,
+ appBinaryFilePath,
+ windowsGraphicalUserInterface: false);
+
+ File.SetAttributes(sourceAppHostMock, FileAttributes.Normal);
+ }
+ }
+
private string PrepareAppHostMockFile(TestDirectory testDirectory, Action<byte[]> customize = null)
{
// For now we're testing the AppHost on Windows PE files only.