Create sfxproj concept
authorDavis Goodin <dagood@microsoft.com>
Fri, 21 Jun 2019 18:46:35 +0000 (13:46 -0500)
committerDavis Goodin <dagood@microsoft.com>
Fri, 21 Jun 2019 21:39:49 +0000 (16:39 -0500)
Arcade is more forceful about having a 1-to-1 mapping between project and intermediate path. This made it tougher to get the existing shared framework infra to work that relies on building a "sharedFramework.csproj" once for each shared framework, overriding the intermediate path.

The new approach is to have one sfxproj per shared framework.

Commit migrated from https://github.com/dotnet/core-setup/commit/9fd9b571c590ec32592e5cab3c54b61f9a22d225

src/installer/pkg/packaging-tools/framework.sharedfx.props [new file with mode: 0644]
src/installer/pkg/packaging-tools/framework.sharedfx.targets [moved from src/installer/pkg/packaging-tools/sharedFramework/sharedFramework.csproj with 68% similarity]
src/installer/pkg/packaging-tools/packaging-tools.props
src/installer/pkg/packaging-tools/packaging-tools.targets
src/installer/pkg/projects/netcoreapp/sfx/Microsoft.NETCore.App.SharedFx.sfxproj [new file with mode: 0644]
src/installer/pkg/projects/windowsdesktop/sfx/Microsoft.WindowsDesktop.App.SharedFx.sfxproj [new file with mode: 0644]

diff --git a/src/installer/pkg/packaging-tools/framework.sharedfx.props b/src/installer/pkg/packaging-tools/framework.sharedfx.props
new file mode 100644 (file)
index 0000000..ddd7592
--- /dev/null
@@ -0,0 +1,42 @@
+<Project>
+  <!--
+    Shared properties specific to shared framework projects (sfxproj).
+  -->
+
+  <PropertyGroup>
+    <TargetFramework>$(NETCoreAppFramework)</TargetFramework>
+    <PackageId>unused</PackageId>
+
+    <ProjectDepsFileName>$(SharedFrameworkName).deps.json</ProjectDepsFileName>
+
+    <!--
+      When blank, MicrosoftNETPlatformLibrary defaults to Microsoft.NETCore.App. This property
+      causes the SDK to trim dependencies when publishing a framework-dependent app. We want to be
+      able to create Microsoft.NETCore.App here, so disable this behavior. Use a non-'' value to
+      avoid the default and make it hint at the goal in case it shows up in a weird place.
+    -->
+    <MicrosoftNETPlatformLibrary>do-not-consider-existing-platform</MicrosoftNETPlatformLibrary>
+
+    <!-- Only Restore from our built packages -->
+    <RestoreSources>$(ArtifactsShippingPackagesDir)</RestoreSources>
+    <AddDotnetfeedProjectSource>false</AddDotnetfeedProjectSource>
+    <RestoreAllBuildRids>false</RestoreAllBuildRids>
+    <!-- Ensure only this repo's NuGet.config file is used. -->
+    <RestoreConfigFile>$(ProjectDir)NuGet.config</RestoreConfigFile>
+    <!-- Use repo-restored packages for platforms and targets dependencies -->
+    <RestoreFallbackFolders>$(PackagesDir)</RestoreFallbackFolders>
+    <!-- Don't error due to lack of runtime-specific deps, we're referencing those directly -->
+    <EnsureRuntimePackageDependencies>false</EnsureRuntimePackageDependencies>
+    <!-- Use a project-local packages folder. 'p', not 'packages': max path breathing room. -->
+    <RestorePackagesPath>$(IntermediateOutputPath)p</RestorePackagesPath>
+    <!-- Do not build or nor build in publish output or deps -->
+    <NoBuild>true</NoBuild>
+
+    <CopyBuildOutputToPublishDirectory>false</CopyBuildOutputToPublishDirectory>
+    <CopyOutputSymbolsToPublishDirectory>false</CopyOutputSymbolsToPublishDirectory>
+    <IncludeMainProjectInDepsFile>false</IncludeMainProjectInDepsFile>
+
+    <GenerateSharedFramework>true</GenerateSharedFramework>
+  </PropertyGroup>
+
+</Project>
@@ -1,68 +1,32 @@
-<Project Sdk="Microsoft.NET.Sdk" InitialTargets="GetPackageReference" DefaultTargets="Restore;Publish">
+<Project>
   <!--
-    This project lays out a shared framework using the SDK targets.
+    Shared targets specific to shared framework projects (sfxproj).
   -->
 
-  <UsingTask TaskName="ProcessSharedFrameworkDeps" AssemblyFile="$(LocalBuildToolsTaskDir)core-setup.tasks.dll" />
+  <UsingTask TaskName="ProcessSharedFrameworkDeps" AssemblyFile="$(LocalBuildToolsTaskFile)" />
 
-  <PropertyGroup>
-    <TargetFramework>$(NETCoreAppFramework)</TargetFramework>
-    <RuntimeIdentifier>$(PackageRID)</RuntimeIdentifier>
-    <PackageId>unused</PackageId>
-
-    <ProjectDepsFileName>$(SharedFrameworkName).deps.json</ProjectDepsFileName>
+  <Target Name="GetPackageReference"
+          DependsOnTargets="GetProductVersions"
+          BeforeTargets="CollectPackageReferences">
+    <PropertyGroup>
+      <SfxVersion Condition="'$(SfxVersion)' == ''">$(ProductVersion)</SfxVersion>
+      <SfxPackageIdentity Condition="'$(SfxPackageIdentity)' == ''">$(SfxIdentity)</SfxPackageIdentity>
+    </PropertyGroup>
 
     <!--
-      When blank, MicrosoftNETPlatformLibrary defaults to Microsoft.NETCore.App. This property
-      causes the SDK to trim dependencies when publishing a framework-dependent app. We want to be
-      able to create Microsoft.NETCore.App here, so disable this behavior. Use a non-'' value to
-      avoid the default and make it hint at the goal in case it shows up in a weird place.
+      Get rid of NuGet's ExcludeRestorePackageImports=true so that the packaging tooling is
+      accessible for Id and version.
     -->
-    <MicrosoftNETPlatformLibrary>do-not-consider-existing-platform</MicrosoftNETPlatformLibrary>
-
-    <!-- Don't reference NETCore.App -->
-    <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
-    <!-- Only Restore from our built packages -->
-    <RestoreSources>$(PackageOutputPath)</RestoreSources>
-    <!-- Ensure only this repo's NuGet.config file is used. -->
-    <RestoreConfigFile>$(ProjectDir)NuGet.config</RestoreConfigFile>
-    <!-- Use repo-restored packages for platforms and targets dependencies -->
-    <RestoreFallbackFolders>$(PackagesDir)</RestoreFallbackFolders>
-    <DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
-    <!-- Don't error due to lack of runtime-specific deps, we're referencing those directly -->
-    <EnsureRuntimePackageDependencies>false</EnsureRuntimePackageDependencies>
-    <!-- Use a project-local packages folder. 'p', not 'packages': max path breathing room. -->
-    <RestorePackagesPath>$(IntermediateOutputPath)p</RestorePackagesPath>
-    <!-- Do not build or nor build in publish output or deps -->
-    <NoBuild>true</NoBuild>
-    <CopyBuildOutputToPublishDirectory>false</CopyBuildOutputToPublishDirectory>
-    <CopyOutputSymbolsToPublishDirectory>false</CopyOutputSymbolsToPublishDirectory>
-    <IncludeMainProjectInDepsFile>false</IncludeMainProjectInDepsFile>
-  </PropertyGroup>
-
-  <Target Name="GetPackageReference">
-    <Error Condition="'$(SharedFrameworkName)' == ''" Text="'SharedFrameworkName' property not specified." />
-    <Error Condition="'$(SharedFrameworkPkgprojFile)' == ''" Text="'SharedFrameworkPkgprojFile' property not specified." />
-
     <MSBuild
-      Projects="$(SharedFrameworkPkgprojFile)"
+      Projects="@(PkgProjectReference)"
       Targets="GetPackageIdentity"
-      RemoveProperties="Configuration">
-      <Output TaskParameter="TargetOutputs" ItemName="SfxIdentity" />
+      Properties="ExcludeRestorePackageImports=false">
+      <Output TaskParameter="TargetOutputs" ItemName="FrameworkPackageReference" />
     </MSBuild>
 
-    <PropertyGroup>
-      <SfxIdentity>%(SfxIdentity.Identity)</SfxIdentity>
-      <SfxVersion>%(SfxIdentity.Version)</SfxVersion>
-      <PublishDir>$(SharedFrameworkLayoutDir)shared/$(SfxIdentity)/$(SfxVersion)/</PublishDir>
-    </PropertyGroup>
-
-    <MSBuild
-      Projects="$(SharedFrameworkPkgprojFile)"
-      Targets="GetSharedFrameworkPackageReferences"
-      RemoveProperties="Configuration">
-      <Output TaskParameter="TargetOutputs" ItemName="PackageReference" />
-    </MSBuild>
+    <ItemGroup>
+      <PackageReference Include="@(FrameworkPackageReference)" AllowExplicitVersion="true" />
+    </ItemGroup>
   </Target>
 
   <!--
     </PropertyGroup>
 
     <WriteLinesToFile
-      File="$(PublishDir)$(SharedFrameworkName).runtimeconfig.json"
+      File="$(PublishDir)$(MSBuildProjectName).runtimeconfig.json"
       Lines="$(_runtimeConfigContent)"
       Overwrite="true" />
   </Target>
     <!-- Generate .version file -->
     <ItemGroup>
       <VersionLines Include="$(LatestCommit)" />
-      <VersionLines Include="%(PackageReference.Version)" />
+      <VersionLines Include="$(SfxVersion)" />
     </ItemGroup>
 
     <WriteLinesToFile
           Condition="'$(GenerateRuntimeGraph)' == 'true'"
           AfterTargets="Publish">
     <PropertyGroup>
-      <SharedFrameworkAssetsFile>$(IntermediateOutputPath)/project.assets.json</SharedFrameworkAssetsFile>
       <SharedFrameworkDepsFile>$(PublishDir)$(ProjectDepsFileName)</SharedFrameworkDepsFile>
       <RuntimeGraphGeneratorRuntime Condition="'$(OSGroup)'=='Windows_NT'">win</RuntimeGraphGeneratorRuntime>
       <RuntimeGraphGeneratorRuntime Condition="'$(OSGroup)'=='OSX'">osx</RuntimeGraphGeneratorRuntime>
       <TrimPkgsFromDeps Include="microsoft.netcore.dotnethostresolver" />
     </ItemGroup>
 
-    <ProcessSharedFrameworkDeps AssetsFilePath="$(SharedFrameworkAssetsFile)"
+    <ProcessSharedFrameworkDeps AssetsFilePath="$(ProjectAssetsFile)"
                                 DepsFilePath="$(SharedFrameworkDepsFile)"
                                 PackagesToRemove="@(TrimPkgsFromDeps)"
                                 Runtime="$(RuntimeGraphGeneratorRuntime)"
-                                BuildToolsTaskDir="$(BuildToolsTaskDir)" />
+                                BuildTasksAssemblyPath="$(PackagingTaskDir)Microsoft.DotNet.Build.Tasks.Packaging.dll" />
   </Target>
 
   <Target Name="CleanPackages" BeforeTargets="Clean">
     <Delete Files="$(ProjectAssetsFile)" />
   </Target>
 
+  <!--
+    Ensure the pkgproj is already built. This isn't a real ProjectReference because the SDK doesn't
+    seem to handle pkgproj nicely for Publish. For now we're using its nupkg directly.
+  -->
+  <Target Name="BuildPkgProjectReferences">
+    <MSBuild Projects="@(PkgProjectReference)" Targets="Build" />
+  </Target>
+
+  <Target Name="SetPublishDir"
+          DependsOnTargets="GetPackageReference">
+    <PropertyGroup>
+      <PublishDir>$(SharedFrameworkLayoutDir)shared/$(SfxIdentity)/$(SfxVersion)/</PublishDir>
+    </PropertyGroup>
+  </Target>
+
+  <!-- Target overrides -->
+
+  <!--
+    Redefine build. Shared framework generation uses pkgproj packages.
+  -->
+  <Target Name="Build"
+          DependsOnTargets="
+            BuildPkgProjectReferences;
+            SetPublishDir;
+            CleanPackages;
+            Restore;
+            Publish;
+            GenerateInstallers" />
+
 </Project>
index 233d7de..b5e0b50 100644 (file)
@@ -1,5 +1,7 @@
 <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
+  <Import Project="framework.sharedfx.props" Condition="'$(MSBuildProjectExtension)' == '.sfxproj'" />
+
   <PropertyGroup>
     <InstallerSourceIntermediateOutputDir>$(ObjDir)$(InstallerSourceOSPlatformConfig)\$(MSBuildProjectName)\</InstallerSourceIntermediateOutputDir>
 
index 5cf2496..b602dda 100644 (file)
@@ -6,6 +6,7 @@
   -->
   <Import Project="framework.dependency.targets" Condition="'$(MSBuildProjectExtension)' == '.depproj'" />
   <Import Project="framework.packaging.targets" Condition="'$(MSBuildProjectExtension)' == '.pkgproj'" />
+  <Import Project="framework.sharedfx.targets" Condition="'$(MSBuildProjectExtension)' == '.sfxproj'" />
 
   <Import Project="installer.targets" />
 
diff --git a/src/installer/pkg/projects/netcoreapp/sfx/Microsoft.NETCore.App.SharedFx.sfxproj b/src/installer/pkg/projects/netcoreapp/sfx/Microsoft.NETCore.App.SharedFx.sfxproj
new file mode 100644 (file)
index 0000000..7caad43
--- /dev/null
@@ -0,0 +1,35 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <SfxIdentity>Microsoft.NETCore.App</SfxIdentity>
+    <SfxPackageIdentity>$(SfxIdentity).Internal</SfxPackageIdentity>
+
+    <!-- Lay out the sfx in the legacy location for old packaging to keep working for now. -->
+    <SharedFrameworkLayoutDir>$(SharedFrameworkPublishDir)</SharedFrameworkLayoutDir>
+
+    <GenerateRuntimeGraph>true</GenerateRuntimeGraph>
+
+    <!-- These components are installed by the root shared framework, but not others. -->
+    <IncludeWerRelatedKeys>true</IncludeWerRelatedKeys>
+    <IncludeBreadcrumbStoreFolder>true</IncludeBreadcrumbStoreFolder>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PkgProjectReference Include="..\pkg\legacy\Microsoft.NETCore.App.Internal.pkgproj" />
+    <PkgProjectReference Include="..\pkg\legacy\Microsoft.NETCore.App.pkgproj" />
+    <PkgProjectReference Include="..\..\Microsoft.NETCore.DotNetHost\Microsoft.NETCore.DotNetHost.pkgproj" />
+  </ItemGroup>
+
+  <!--
+    Make sure the installer file is generated with the old infra's name and location. This allows
+    the existing infra to bundle it without any changes.
+  -->
+  <Target Name="PutSharedFrameworkMsiInLegacyLocation"
+          DependsOnTargets="GetInstallerLocations"
+          BeforeTargets="GetInstallerProperties">
+    <PropertyGroup>
+      <InstallerFile>$(SharedFrameworkInstallerFile)</InstallerFile>
+    </PropertyGroup>
+  </Target>
+
+</Project>
diff --git a/src/installer/pkg/projects/windowsdesktop/sfx/Microsoft.WindowsDesktop.App.SharedFx.sfxproj b/src/installer/pkg/projects/windowsdesktop/sfx/Microsoft.WindowsDesktop.App.SharedFx.sfxproj
new file mode 100644 (file)
index 0000000..8aa529c
--- /dev/null
@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <SfxIdentity>Microsoft.WindowsDesktop.App</SfxIdentity>
+
+    <GenerateCompressedArchive>true</GenerateCompressedArchive>
+    <GenerateNetCoreAppRuntimeConfig>true</GenerateNetCoreAppRuntimeConfig>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PkgProjectReference Include="..\pkg\Microsoft.WindowsDesktop.App.pkgproj" />
+  </ItemGroup>
+
+</Project>