public static void Create()

in src/Tasks/Microsoft.NET.Build.Tasks/AppHost.cs [32:94]


        public static void Create(
            string appHostSourceFilePath,
            string appHostDestinationFilePath,
            string appBinaryFilePath,
            bool windowsGraphicalUserInterface = false,
            string intermediateAssembly = null,
            Logger log = null)
        {
            var bytesToWrite = Encoding.UTF8.GetBytes(appBinaryFilePath);
            if (bytesToWrite.Length > 1024)
            {
                throw new BuildErrorException(Strings.FileNameIsTooLong, appBinaryFilePath);
            }

            var destinationDirectory = new FileInfo(appHostDestinationFilePath).Directory.FullName;
            if (!Directory.Exists(destinationDirectory))
            {
                Directory.CreateDirectory(destinationDirectory);
            }

            // Copy apphost to destination path so it inherits the same attributes/permissions.
            File.Copy(appHostSourceFilePath, appHostDestinationFilePath, overwrite: true);

            // Re-write the destination apphost with the proper contents.
            bool appHostIsPEImage = false;
            using (var memoryMappedFile = MemoryMappedFile.CreateFromFile(appHostDestinationFilePath))
            {
                using (MemoryMappedViewAccessor accessor = memoryMappedFile.CreateViewAccessor())
                {
                    SearchAndReplace(accessor, AppBinaryPathPlaceholderSearchValue, bytesToWrite, appHostSourceFilePath);

                    appHostIsPEImage = IsPEImage(accessor);

                    if (windowsGraphicalUserInterface)
                    {
                        if (!appHostIsPEImage)
                        {
                            throw new BuildErrorException(Strings.AppHostNotWindows, appHostSourceFilePath);
                        }

                        SetWindowsGraphicalUserInterfaceBit(accessor, appHostSourceFilePath);
                    }
                }
            }

            if (intermediateAssembly != null && appHostIsPEImage)
            {
                if (ResourceUpdater.IsSupportedOS())
                {
                    // Copy resources from managed dll to the apphost
                    new ResourceUpdater(appHostDestinationFilePath)
                        .AddResourcesFromPEImage(intermediateAssembly)
                        .Update();
                }
                else if (log != null)
                {
                    log.LogWarning(Strings.AppHostCustomizationRequiresWindowsHostWarning);
                }
            }

            // Memory-mapped write does not updating last write time
            File.SetLastWriteTimeUtc(appHostDestinationFilePath, DateTime.UtcNow);
        }