示例#1
0
            public SharedTestState()
            {
                // The dotnetSDKLookup dir will contain some folders and files that will be
                // necessary to perform the tests
                string baseDir = Path.Combine(TestArtifact.TestArtifactsPath, "dotnetSDKLookup");

                BaseDir          = SharedFramework.CalculateUniqueTestDirectory(baseDir);
                _baseDirArtifact = new TestArtifact(BaseDir);

                // The three tested locations will be the cwd and the exe dir. cwd is no longer supported.
                //     All dirs will be placed inside the base folder

                BuiltDotNet = new DotNetCli(Path.Combine(TestArtifact.TestArtifactsPath, "sharedFrameworkPublish"));

                RepoDirectories = new RepoDirectoriesProvider();

                // Executable location is created per test as each test adds a different set of SDK versions

                var currentWorkingSdk = new DotNetBuilder(BaseDir, BuiltDotNet.BinPath, "current")
                                        .AddMockSDK("10000.0.0", "9999.0.0")
                                        .Build();

                CurrentWorkingDir = currentWorkingSdk.BinPath;

                TestAssetsPath = Path.Combine(RepoDirectories.TestAssetsFolder, "TestUtils", "SDKLookup");
            }
        public void Bundle_Framework_dependent_NoBundleEntryPoint()
        {
            var fixture = sharedTestState.TestFrameworkDependentFixture.Copy();

            UseFrameworkDependentHost(fixture);
            var singleFile = BundleHelper.BundleApp(fixture, BundleOptions.None);

            string dotnetWithMockHostFxr = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "guiErrors"));

            using (new TestArtifact(dotnetWithMockHostFxr))
            {
                Directory.CreateDirectory(dotnetWithMockHostFxr);
                var dotnetBuilder = new DotNetBuilder(dotnetWithMockHostFxr, sharedTestState.RepoDirectories.BuiltDotnet, "mockhostfxrFrameworkMissingFailure")
                                    .RemoveHostFxr()
                                    .AddMockHostFxr(new Version(2, 2, 0));
                var dotnet = dotnetBuilder.Build();

                // Run the bundled app (extract files)
                RunTheApp(singleFile, dotnet)
                .Should()
                .Fail()
                .And.HaveStdErrContaining("You must install or update .NET to run this application.")
                .And.HaveStdErrContaining("App host version:")
                .And.HaveStdErrContaining("apphost_version=");
            }
        }
示例#3
0
            public SharedTestState()
            {
                var dotNet = new DotNetBuilder(BaseDirectory, Path.Combine(TestArtifact.TestArtifactsPath, "sharedFrameworkPublish"), "mockRuntime")
                             .AddMicrosoftNETCoreAppFrameworkMockCoreClr(NetCoreAppVersion)
                             .Build();

                DotNetRoot = dotNet.BinPath;

                HostFxrPath = Path.Combine(
                    dotNet.GreatestVersionHostFxrPath,
                    RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostfxr"));

                string appDir = Path.Combine(BaseDirectory, "app");

                Directory.CreateDirectory(appDir);
                AppPath = Path.Combine(appDir, "App.dll");
                File.WriteAllText(AppPath, string.Empty);

                RuntimeConfig.FromFile(Path.Combine(appDir, "App.runtimeconfig.json"))
                .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, NetCoreAppVersion))
                .WithProperty(AppPropertyName, AppPropertyValue)
                .Save();

                AppPath_MultiProperty = Path.Combine(appDir, "App_MultiProperty.dll");
                File.WriteAllText(AppPath_MultiProperty, string.Empty);

                RuntimeConfig.FromFile(Path.Combine(appDir, "App_MultiProperty.runtimeconfig.json"))
                .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, NetCoreAppVersion))
                .WithProperty(AppPropertyName, AppPropertyValue)
                .WithProperty(AppMultiPropertyName, AppMultiPropertyValue)
                .Save();

                string configDir = Path.Combine(BaseDirectory, "config");

                Directory.CreateDirectory(configDir);
                RuntimeConfigPath = Path.Combine(configDir, "Component.runtimeconfig.json");
                RuntimeConfig.FromFile(RuntimeConfigPath)
                .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, NetCoreAppVersion))
                .WithProperty(ConfigPropertyName, ConfigPropertyValue)
                .Save();

                RuntimeConfigPath_MultiProperty = Path.Combine(configDir, "Component_MultiProperty.runtimeconfig.json");
                RuntimeConfig.FromFile(RuntimeConfigPath_MultiProperty)
                .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, NetCoreAppVersion))
                .WithProperty(ConfigPropertyName, ConfigPropertyValue)
                .WithProperty(ConfigMultiPropertyName, ConfigMultiPropertyValue)
                .Save();

                string secondaryDir = Path.Combine(BaseDirectory, "secondary");

                Directory.CreateDirectory(secondaryDir);
                SecondaryRuntimeConfigPath = Path.Combine(secondaryDir, "Secondary.runtimeconfig.json");
                RuntimeConfig.FromFile(SecondaryRuntimeConfigPath)
                .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, NetCoreAppVersion))
                .WithProperty(SecondaryConfigPropertyName, SecondaryConfigPropertyValue)
                .Save();
            }
示例#4
0
 protected override void CustomizeDotNetWithNetCoreApp(DotNetBuilder builder)
 {
     builder.AddFramework(
         HighWare,
         "1.1.1",
         runtimeConfig => runtimeConfig.WithFramework(MicrosoftNETCoreApp, "4.0.0"),
         path => NetCoreAppBuilder.ForNETCoreApp(HighWare, RepoDirectories.TargetRID)
         .WithProject(HighWare, "1.1.1", p => p
                      .WithAssemblyGroup(null, g => g
                                         .WithAsset(TestAssemblyWithNoVersions + ".dll")
                                         .WithAsset(TestAssemblyWithAssemblyVersion + ".dll", rf => rf.WithVersion("2.1.1.2", null))
                                         .WithAsset(TestAssemblyWithFileVersion + ".dll", rf => rf.WithVersion(null, "3.2.2.2"))
                                         .WithAsset(TestAssemblyWithBothVersions + ".dll", rf => rf.WithVersion("2.1.1.0", "3.2.2.0"))))
         .Build(new TestApp(path, HighWare)));
 }
示例#5
0
        private static async Task Main(
            string[] arguments,
            CancellationToken cancellationToken,
            bool errorIfToolConfigNotExists = false
            )
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            _errorIfToolConfigNotExists         = errorIfToolConfigNotExists;
            string enviroinmentVarsConfigPath        = Path.Combine(Environment.CurrentDirectory, _enviroinmentVarsConfigFile);
            string buildToolConfigPath               = Path.Combine(Environment.CurrentDirectory, _dotnetBuildToolConfig);
            Task <BuilderOptions> setToolOptionsTask = SetToolOptionsAsync(buildToolConfigPath);
            Task setEnvVarsTask = SetEnviroinmentVariablesAsync(enviroinmentVarsConfigPath);

            BuilderOptions options = await setToolOptionsTask;
            await          setEnvVarsTask;

            await DotNetBuilder.CreatBuilderAsync(options, cancellationToken).ExecuteTargetsAsync(arguments);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Please specify config postfix:");

            var configFilePostFix = Console.ReadLine();

            var dt = DateTime.Now;

            var solution = JsonSerializer.Deserialize <Solution>
                               (File.ReadAllText(Environment.CurrentDirectory + $"\\config-{configFilePostFix}.json"));

            FilterProjects(args, solution);

            GitRepositoryPuller.Pull(solution.RepositoryPath);

            foreach (var project in solution.Projects)
            {
                DotNetBuilder.Release(Path.Combine(solution.RepositoryPath, project.ProjectPath), GetPath(solution, project, PathType.Publish));

                IISWebSiteManager.Stop(project.SiteName);

                DirectoryFullGraphCopier.Copy(GetPath(solution, project, PathType.WebSite), GetPath(solution, project, PathType.BackUp));

                DirectoryFullGraphCopier.Copy(GetPath(solution, project, PathType.Publish), GetPath(solution, project, PathType.WebSite));

                foreach (var solutionSetting in solution.SolutionSettings)
                {
                    FileContentReplacer.ReplaceByKey(GetPath(solution, project, PathType.WebSite, solutionSetting.FileName), solutionSetting.Key, solutionSetting.NewValue);
                }

                foreach (var projectSetting in project.ProjectSettings)
                {
                    FileContentReplacer.ReplaceByKey(GetPath(solution, project, PathType.WebSite, projectSetting.FileName), projectSetting.Key, projectSetting.NewValue);
                }

                IISWebSiteManager.Start(project.SiteName);
            }

            var period = DateTime.Now - dt;

            Console.WriteLine($"Finished in: {period}");

            Console.ReadLine();
        }
            public SharedTestState()
            {
                DotNet = new DotNetBuilder(BaseDirectory, Path.Combine(TestArtifact.TestArtifactsPath, "sharedFrameworkPublish"), "mockRuntime")
                         .AddMicrosoftNETCoreAppFrameworkMockCoreClr(NetCoreAppVersion)
                         .Build();

                HostFxrPath = Path.Combine(
                    DotNet.GreatestVersionHostFxrPath,
                    RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostfxr"));

                AppDirectory = Path.Combine(BaseDirectory, "app");
                Directory.CreateDirectory(AppDirectory);
                AppPath = Path.Combine(AppDirectory, "App.dll");
                File.WriteAllText(AppPath, string.Empty);

                RuntimeConfig.FromFile(Path.Combine(AppDirectory, "App.runtimeconfig.json"))
                .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, NetCoreAppVersion))
                .Save();
            }
示例#8
0
        [PlatformSpecific(TestPlatforms.Windows)] // GUI app host is only supported on Windows.
        public void Bundled_Framework_dependent_App_GUI_DownlevelHostFxr_ErrorDialog(BundleOptions options)
        {
            var fixture = sharedTestState.TestFrameworkDependentFixture.Copy();

            UseFrameworkDependentHost(fixture);
            var singleFile = BundleHelper.BundleApp(fixture, options);

            AppHostExtensions.SetWindowsGraphicalUserInterfaceBit(singleFile);

            string dotnetWithMockHostFxr = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "bundleErrors"));

            using (new TestArtifact(dotnetWithMockHostFxr))
            {
                Directory.CreateDirectory(dotnetWithMockHostFxr);
                string expectedErrorCode = Constants.ErrorCode.BundleExtractionFailure.ToString("x");

                var dotnetBuilder = new DotNetBuilder(dotnetWithMockHostFxr, sharedTestState.RepoDirectories.BuiltDotnet, "mockhostfxrBundleVersionFailure")
                                    .RemoveHostFxr()
                                    .AddMockHostFxr(new Version(5, 0, 0));
                var dotnet = dotnetBuilder.Build();

                Command command = Command.Create(singleFile)
                                  .EnableTracingAndCaptureOutputs()
                                  .DotNetRoot(dotnet.BinPath, sharedTestState.RepoDirectories.BuildArchitecture)
                                  .MultilevelLookup(false)
                                  .Start();

                WindowsUtils.WaitForPopupFromProcess(command.Process);
                command.Process.Kill();

                command
                .WaitForExit(true)
                .Should().Fail()
                .And.HaveStdErrContaining("Bundle header version compatibility check failed.")
                .And.HaveStdErrContaining($"Showing error dialog for application: '{Path.GetFileName(singleFile)}' - error code: 0x{expectedErrorCode}")
                .And.HaveStdErrContaining("apphost_version=");
            }
        }
示例#9
0
 protected virtual void CustomizeDotNetWithNetCoreApp(DotNetBuilder builder)
 {
 }
示例#10
0
        public override async Task <int> Execute(AssemblyModuleBuilderTaskArguments arguments, string[] args)
        {
            Console.WriteLine($"Snowball Assembly Builder version {Assembly.GetEntryAssembly().GetName().Version}");
            var cwd = arguments.SourceDirectory != null
                ? new DirectoryInfo(Path.GetFullPath(arguments.SourceDirectory))
                : DirectoryProvider.WorkingDirectory;

            Console.WriteLine($"Attempting to build module in {cwd.FullName}...");
            if (!DirectoryProvider.IsProjectDirectory(cwd))
            {
                throw new FileNotFoundException("Error! No valid project file found.");
            }

            if (!DirectoryProvider.IsModuleDirectory(cwd))
            {
                throw new InvalidDataException(
                          "Error! No valid module.json found. Check for JSON errors or missing file.");
            }

            (var projectFile, var moduleFile) = DirectoryProvider.GetProjectFiles(cwd);
            ModuleDefinition module;

            try
            {
                module = JsonConvert.DeserializeObject <ModuleDefinition>(File.ReadAllText(moduleFile?.FullName));
            }
            catch
            {
                throw new InvalidDataException(
                          "Error! No valid module.json found. Check for JSON errors or missing file.");
            }

            if (!module.Entry.EndsWith(".dll") || module.Loader != "assembly")
            {
                throw new InvalidDataException(
                          "Error! Module is not a proper assembly module, can not pack non-assembly modules!");
            }

            var    projectXml   = XDocument.Parse(File.ReadAllText(projectFile.FullName)).Root.Descendants();
            string assemblyName = (from groups in projectXml
                                   from element in groups.Descendants()
                                   where element.Name.LocalName == "AssemblyName"
                                   select element.Value).FirstOrDefault() ??
                                  Path.GetFileNameWithoutExtension(projectFile.Name);

            if (assemblyName != Path.GetFileNameWithoutExtension(module.Entry))
            {
                throw new InvalidOperationException(
                          $"Error! Entry point {module.Entry} is not consistent with output assembly name {assemblyName}!");
            }

            string targetFramework = (from groups in projectXml
                                      from element in groups.Descendants()
                                      where element.Name.LocalName == "TargetFramework"
                                      select element.Value).FirstOrDefault();

            if (targetFramework != "netcoreapp2.2")
            {
                throw new InvalidOperationException($"Error! Assembly modules must target framework netcoreapp2.2");
            }

            Console.WriteLine($"Found module {module.Entry}");
            var builder = new DotNetBuilder(module, projectFile, arguments.OutputDirectory, arguments.MsbuildArgs);

            Console.WriteLine("Cleaning and building module...");

            try
            {
                DirectoryInfo buildResult = await builder.Build();

                Console.WriteLine($"Finished building module at {Environment.NewLine} {buildResult.FullName}");
                return(0);
            }
            catch (Exception ex)
            {
                throw new Exception($"Unable to build module due to {ex.Message}", ex);
            }
        }