Skip to content

Commit

Permalink
Implement building with an apphost by default.
Browse files Browse the repository at this point in the history
This commit implements building with an apphost by default, without specifying
a `RuntimeIdentifier`.

This works by using the runtime identifier of the SDK to restore the apphost
package.  The apphost will be the only native asset copied to the build output.

Fixes dotnet/cli#6237.
  • Loading branch information
Peter Huene committed Oct 12, 2018
1 parent 1617a17 commit e617c0a
Show file tree
Hide file tree
Showing 25 changed files with 122 additions and 167 deletions.
6 changes: 1 addition & 5 deletions src/Tasks/Common/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,6 @@ The following are names of parameters or literal values and should not be transl
<value>NETSDK1065: Cannot find app host for {0}. {0} could be an invalid runtime identifier (RID). For more information about RID, see https://aka.ms/rid-catalog.</value>
<comment>{StrBegin="NETSDK1065: "}</comment>
</data>
<data name="CannotUseAppHostWithoutRuntimeIdentifier" xml:space="preserve">
<value>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</value>
<comment>{StrBegin="NETSDK1066: "}</comment>
</data>
<data name="CannotUseSelfContainedWithoutAppHost" xml:space="preserve">
<value>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</value>
<comment>{StrBegin="NETSDK1067: "}</comment>
Expand Down Expand Up @@ -432,4 +428,4 @@ The following are names of parameters or literal values and should not be transl
<value>NETSDK1078: Unable to use '{0}' as application host executable because it's not a Windows PE file.</value>
<comment>{StrBegin="NETSDK1078: "}</comment>
</data>
</root>
</root>
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">NETSDK1001: Je potřeba zadat alespoň jednu možnou cílovou architekturu.</target>
<note>{StrBegin="NETSDK1001: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="translated">NETSDK1066: RuntimeIdentifier musí být zadaný, aby se mohla publikovat aplikace závislá na architektuře s hostitelem aplikace.</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="translated">NETSDK1067: K používání hostitele aplikace se vyžadují samostatné (nezávislé) aplikace. Nastavte možnost SelfContained na false nebo nastavte UseAppHost na true.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">NETSDK1001: Geben Sie mindestens ein mögliches Zielframework an.</target>
<note>{StrBegin="NETSDK1001: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="translated">NETSDK1066: Ein RuntimeIdentifier muss angegeben werden, um eine frameworkabhängige Anwendung bei einem Anwendungshost zu veröffentlichen.</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="translated">NETSDK1067: Eigenständige Anwendungen müssen den Anwendungshost verwenden. Legen Sie "SelfContained" auf FALSE oder "UseAppHost" auf TRUE fest.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">NETSDK1001: Debe especificarse al menos una plataforma de destino posible.</target>
<note>{StrBegin="NETSDK1001: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="translated">NETSDK1066: Debe especificarse RuntimeIdentifier para publicar una aplicación dependiente del marco con un host de aplicación.</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="translated">NETSDK1067: Las aplicaciones independientes deben utilizar un host de aplicación. Establezca SelfContained en false o UseAppHost en true.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">NETSDK1001: Vous devez spécifier au moins un framework cible.</target>
<note>{StrBegin="NETSDK1001: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="translated">NETSDK1066: Un RuntimeIdentifier doit être spécifié pour publier une application dépendante du framework avec un hôte d'application.</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="translated">NETSDK1067: Des applications autonomes sont obligatoires pour utiliser l'hôte d'application. Définissez SelfContained avec la valeur false ou UseAppHost avec la valeur true.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">NETSDK1001: è necessario specificare almeno un framework di destinazione possibile.</target>
<note>{StrBegin="NETSDK1001: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="translated">NETSDK1066: è necessario specificare un elemento RuntimeIdentifier per pubblicare un'applicazione dipendente dal framework con un host applicazione.</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="translated">NETSDK1067: con le applicazioni complete è necessario usare l'host applicazione. Impostare SelfContained su false o UseAppHost su true.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">NETSDK1001: 可能性のあるターゲット フレームワークを少なくとも 1 つ指定する必要があります。</target>
<note>{StrBegin="NETSDK1001: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="translated">NETSDK1066: RuntimeIdentifier を指定して、フレームワークに依存するアプリケーションをアプリケーション ホストを使用して発行する必要があります。</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="translated">NETSDK1067: アプリケーション ホストを使用するには、自己完結型のアプリケーションが必要です。SelfContained を false に設定するか、UseAppHost を true に設定してください。</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">NETSDK1001: 가능한 대상 프레임워크를 하나 이상 지정해야 합니다.</target>
<note>{StrBegin="NETSDK1001: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="translated">NETSDK1066: 응용 프로그램 호스트와 함께 프레임워크 종속 응용 프로그램을 게시하려면 RuntimeIdentifier를 지정해야 합니다.</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="translated">NETSDK1067: 응용 프로그램 호스트를 사용하려면 자체 포함 응용 프로그램이 필요합니다. SelfContained를 false로 설정하거나 UseAppHost를 true로 설정하세요.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">NETSDK1001: Należy określić co najmniej jedną możliwą platformę docelową.</target>
<note>{StrBegin="NETSDK1001: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="translated">NETSDK1066: Należy określić identyfikator RuntimeIdentifier, aby opublikować aplikację zależną od platformy za pomocą hosta aplikacji.</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="translated">NETSDK1067: Aplikacje autonomiczne muszą korzystać z hosta aplikacji. Ustaw parametr SelfContained na wartość false lub parametr UseAppHost na wartość true.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">NETSDK1001: É necessário especificar pelo menos uma estrutura de destino possível.</target>
<note>{StrBegin="NETSDK1001: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="translated">NETSDK1066: um RuntimeIdentifier deve ser especificado para publicar um aplicativo dependente de estrutura com um host do aplicativo.</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="translated">NETSDK1067: os aplicativos independentes são necessários para utilizar o host do aplicativo. Defina SelfContained como falso ou defina UseAppHost como verdadeiro.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">NETSDK1001: необходимо указать хотя бы одну целевую платформу.</target>
<note>{StrBegin="NETSDK1001: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="translated">NETSDK1066: для публикации зависящего от платформы приложения на узле приложения необходимо указать RuntimeIdentifierentifier.</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="translated">NETSDK1067: для использования узла приложений требуются автономные приложения. Задайте свойству SelfContained значение false или задайте свойству UseAppHost значение true.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@
<target state="new">NETSDK1013: The TargetFramework value '{0}' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly.</target>
<note>{StrBegin="NETSDK1013: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="new">NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="new">NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">NETSDK1001: 必须指定至少一个可能的目标框架。</target>
<note>{StrBegin="NETSDK1001: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="translated">NETSDK1066: 必须指定一个 RuntimeIdentifier,以通过应用程序主机发布框架依赖型应用程序。</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="translated">NETSDK1067: 需要自包含应用程序才能使用应用程序主机。将 SelfContained 设置为 false,或者将 UseAppHost 设置为 true。</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<target state="translated">NETSDK1001: 至少必須指定一個可能的目標架構。</target>
<note>{StrBegin="NETSDK1001: "}</note>
</trans-unit>
<trans-unit id="CannotUseAppHostWithoutRuntimeIdentifier">
<source>NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host.</source>
<target state="translated">NETSDK1066: 必須指定 RuntimeIdentifier,才可發行具有應用程式主機且與架構相依的應用程式。</target>
<note>{StrBegin="NETSDK1066: "}</note>
</trans-unit>
<trans-unit id="CannotUseSelfContainedWithoutAppHost">
<source>NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.</source>
<target state="translated">NETSDK1067: 需要獨立式應用程式,才可使用該應用程式主機。請將 SelfContained 設定為 False,或是將 UseAppHost 設定為 True。</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class GivenThatWeHaveErrorCodes
{
// Put deleted numeric error codes here.
// For example, if NETSDK1001 is deleted, add 1001 to this list.
1066,
};

[Fact]
Expand All @@ -29,7 +30,7 @@ public void ThereAreNoGapsDuplicatesOrIncorrectlyFormattedCodes()

foreach (var (key, message) in GetMessages())
{
// NB: if we ever need strings that don't have error codes (say because they are not sent to MSBuild),
// NB: if we ever need strings that don't have error codes (say because they are not sent to MSBuild),
// we should use a separate .resx file so that we can preserve this enforcement.
var match = Regex.Match(message, "^NETSDK([0-9]{4}): ");
match.Success
Expand All @@ -47,7 +48,7 @@ public void ThereAreNoGapsDuplicatesOrIncorrectlyFormattedCodes()
int code = _firstCode + i;
codes.Contains(code)
.Should()
.BeTrue(because: $"error codes should not be skipped (NETSDK{code} was not found)");
.BeTrue(because: $"error codes should not be skipped (NETSDK{code} was not found; add to the deleted codes list if intentionally deleted)");
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/Tasks/Microsoft.NET.Build.Tasks/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,22 @@ public static void Create(
string intermediateAssembly = null,
Logger log = null)
{
var hostExtension = Path.GetExtension(appHostSourceFilePath);
var appbaseName = Path.GetFileNameWithoutExtension(appBinaryFilePath);
var bytesToWrite = Encoding.UTF8.GetBytes(appBinaryFilePath);
var destinationDirectory = new FileInfo(appHostDestinationFilePath).Directory.FullName;

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 AppHostSourcePath to ModifiedAppHostPath so it inherits the same attributes\permissions.
// Copy apphost to destination path so it inherits the same attributes/permissions.
File.Copy(appHostSourceFilePath, appHostDestinationFilePath, overwrite: true);

// Re-write ModifiedAppHostPath with the proper contents.
// Re-write the destination apphost with the proper contents.
bool appHostIsPEImage = false;
using (var memoryMappedFile = MemoryMappedFile.CreateFromFile(appHostDestinationFilePath))
{
Expand Down
7 changes: 2 additions & 5 deletions src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
namespace Microsoft.NET.Build.Tasks
{
/// <summary>
/// Creates the AppHost.exe to be used by the published app.
/// This embeds the app dll path into the AppHost.exe and performs additional customizations as requested.
/// Creates the runtime host to be used for an application.
/// This embeds the application DLL path into the apphost and performs additional customizations as requested.
/// </summary>
public class CreateAppHost : TaskBase
{
Expand All @@ -28,9 +28,6 @@ public class CreateAppHost : TaskBase

protected override void ExecuteCore()
{
var hostExtension = Path.GetExtension(AppHostSourcePath);
var appbaseName = Path.GetFileNameWithoutExtension(AppBinaryName);

AppHost.Create(
AppHostSourcePath,
AppHostDestinationPath,
Expand Down
Loading

0 comments on commit e617c0a

Please sign in to comment.