protected override void ExecuteCore()
        {
            List <ITaskItem> knownFrameworkReferences = new List <ITaskItem>();

            if (!string.IsNullOrEmpty(WindowsSdkPackageVersion))
            {
                knownFrameworkReferences.Add(CreateKnownFrameworkReference(WindowsSdkPackageVersion, TargetFrameworkVersion, TargetPlatformVersion));
            }
            else if (UseWindowsSDKPreview)
            {
                var tpv = new Version(TargetPlatformVersion);

                var windowsSdkPackageVersion = $"{tpv.Major}.{tpv.Minor}.{tpv.Build}-preview";

                knownFrameworkReferences.Add(CreateKnownFrameworkReference(windowsSdkPackageVersion, TargetFrameworkVersion, TargetPlatformVersion));
            }
            else
            {
                var normalizedTargetFrameworkVersion = ProcessFrameworkReferences.NormalizeVersion(new Version(TargetFrameworkVersion));
                foreach (var supportedWindowsVersion in WindowsSdkSupportedTargetPlatformVersions)
                {
                    var windowsSdkPackageVersion = supportedWindowsVersion.GetMetadata("WindowsSdkPackageVersion");

                    if (!string.IsNullOrEmpty(windowsSdkPackageVersion))
                    {
                        var minimumNETVersion = supportedWindowsVersion.GetMetadata("MinimumNETVersion");
                        if (!string.IsNullOrEmpty(minimumNETVersion))
                        {
                            var normalizedMinimumVersion = ProcessFrameworkReferences.NormalizeVersion(new Version(minimumNETVersion));
                            if (normalizedMinimumVersion > normalizedTargetFrameworkVersion)
                            {
                                continue;
                            }
                        }

                        knownFrameworkReferences.Add(CreateKnownFrameworkReference(windowsSdkPackageVersion, TargetFrameworkVersion, supportedWindowsVersion.ItemSpec));
                    }
                }
            }

            KnownFrameworkReferences = knownFrameworkReferences.ToArray();
        }
예제 #2
0
        protected override void ExecuteCore()
        {
            var normalizedTargetFrameworkVersion = ProcessFrameworkReferences.NormalizeVersion(new Version(TargetFrameworkVersion));

            var knownAppHostPacksForTargetFramework = KnownAppHostPacks
                                                      .Where(appHostPack =>
            {
                var packTargetFramework = NuGetFramework.Parse(appHostPack.GetMetadata("TargetFramework"));
                return(packTargetFramework.Framework.Equals(TargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) &&
                       ProcessFrameworkReferences.NormalizeVersion(packTargetFramework.Version) == normalizedTargetFrameworkVersion);
            })
                                                      .ToList();

            if (knownAppHostPacksForTargetFramework.Count > 1)
            {
                throw new InvalidOperationException("Multiple KnownAppHostPack items applied to the specified target framework, which is not supposed to happen");
            }

            if (knownAppHostPacksForTargetFramework.Count == 0)
            {
                return;
            }

            var packagesToDownload = new List <ITaskItem>();

            if (!string.IsNullOrEmpty(AppHostRuntimeIdentifier))
            {
                var appHostItem = GetHostItem(
                    AppHostRuntimeIdentifier,
                    knownAppHostPacksForTargetFramework,
                    packagesToDownload,
                    DotNetAppHostExecutableNameWithoutExtension,
                    "AppHost",
                    isExecutable: true,
                    errorIfNotFound: true);

                if (appHostItem != null)
                {
                    AppHost = new ITaskItem[] { appHostItem };
                }

                var singlefileHostItem = GetHostItem(
                    AppHostRuntimeIdentifier,
                    knownAppHostPacksForTargetFramework,
                    packagesToDownload,
                    DotNetSingleFileHostExecutableNameWithoutExtension,
                    "SingleFileHost",
                    isExecutable: true,
                    errorIfNotFound: true);

                if (singlefileHostItem != null)
                {
                    SingleFileHost = new ITaskItem[] { singlefileHostItem };
                }

                var comHostItem = GetHostItem(
                    AppHostRuntimeIdentifier,
                    knownAppHostPacksForTargetFramework,
                    packagesToDownload,
                    DotNetComHostLibraryNameWithoutExtension,
                    "ComHost",
                    isExecutable: false,
                    errorIfNotFound: true);

                if (comHostItem != null)
                {
                    ComHost = new ITaskItem[] { comHostItem };
                }

                var ijwHostItem = GetHostItem(
                    AppHostRuntimeIdentifier,
                    knownAppHostPacksForTargetFramework,
                    packagesToDownload,
                    DotNetIjwHostLibraryNameWithoutExtension,
                    "IjwHost",
                    isExecutable: false,
                    errorIfNotFound: true);

                if (ijwHostItem != null)
                {
                    IjwHost = new ITaskItem[] { ijwHostItem };
                }
            }

            if (PackAsToolShimRuntimeIdentifiers.Length > 0)
            {
                var packAsToolShimAppHostPacks = new List <ITaskItem>();
                foreach (var runtimeIdentifier in PackAsToolShimRuntimeIdentifiers)
                {
                    var appHostItem = GetHostItem(
                        runtimeIdentifier.ItemSpec,
                        knownAppHostPacksForTargetFramework,
                        packagesToDownload,
                        DotNetAppHostExecutableNameWithoutExtension,
                        "AppHost",
                        isExecutable: true,
                        errorIfNotFound: true);

                    if (appHostItem != null)
                    {
                        packAsToolShimAppHostPacks.Add(appHostItem);
                    }
                }
                PackAsToolShimAppHostPacks = packAsToolShimAppHostPacks.ToArray();
            }

            if (OtherRuntimeIdentifiers != null)
            {
                foreach (var otherRuntimeIdentifier in OtherRuntimeIdentifiers)
                {
                    //  Download any apphost packages for other runtime identifiers.
                    //  This allows you to specify the list of RIDs in RuntimeIdentifiers and only restore once,
                    //  and then build for each RuntimeIdentifier without restoring separately.

                    //  We discard the return value, and pass in some bogus data that won't be used, because
                    //  we won't use the assets from the apphost pack in this build.
                    GetHostItem(otherRuntimeIdentifier,
                                knownAppHostPacksForTargetFramework,
                                packagesToDownload,
                                hostNameWithoutExtension: "unused",
                                itemName: "unused",
                                isExecutable: true,
                                errorIfNotFound: false);
                }
            }

            if (packagesToDownload.Any())
            {
                PackagesToDownload = packagesToDownload.ToArray();
            }
        }