private static int Main(string[] args) { Console.WriteLine(@"Bootstrapping: " + args[0]); var xenkoDir = Environment.GetEnvironmentVariable("SiliconStudioXenkoDir"); var xenkoPkgPath = UPath.Combine(xenkoDir, new UFile("Xenko.xkpkg")); var session = PackageSession.Load(xenkoPkgPath); var generator = TemplateSampleGenerator.Default; var logger = new LoggerResult(); var parameters = new TemplateGeneratorParameters { Session = session.Session }; var outputPath = UPath.Combine(new UDirectory(xenkoDir), new UDirectory("samplesGenerated")); outputPath = UPath.Combine(outputPath, new UDirectory(args[0])); var xenkoTemplates = session.Session.Packages.First().Templates; parameters.Description = xenkoTemplates.First(x => x.Group.StartsWith("Samples") && x.Id == new Guid(args[1])); parameters.Name = args[0]; parameters.Namespace = args[0]; parameters.OutputDirectory = outputPath; parameters.Logger = logger; generator.Generate(parameters); var updaterTemplate = xenkoTemplates.First(x => x.FullPath.ToString().EndsWith("UpdatePlatforms.xktpl")); parameters.Description = updaterTemplate; var updater = UpdatePlatformsTemplateGenerator.Default; var gameSettingsAsset = session.Session.Packages.Last().GetGameSettingsAsset(); var renderingSettings = gameSettingsAsset.Get <RenderingSettings>(); var updateParams = new GameTemplateParameters { Common = parameters, ForcePlatformRegeneration = true, GraphicsProfile = renderingSettings.DefaultGraphicsProfile, IsHDR = false, Orientation = (DisplayOrientation)renderingSettings.DisplayOrientation, Platforms = AssetRegistry.SupportedPlatforms.ToList() }; updater.Generate(updateParams); Console.WriteLine(logger.ToText()); return(logger.HasErrors ? 1 : 0); }
static void Main() { var clock = Stopwatch.StartNew(); for (int i = 0; i < 10; i++) { var session = PackageSession.Load(@"E:\Code\SengokuRun\SengokuRun\WindowsLauncher\GameAssets\Assets.xkpkg"); } var elapsed = clock.ElapsedMilliseconds; Console.WriteLine("{0}ms", elapsed); }
public void TestBasicPackageCreateSaveLoad() { PackageSessionPublicHelper.FindAndSetMSBuildVersion(); var dirPath = DirectoryTestBase + @"TestBasicPackageCreateSaveLoad"; string testGenerated1 = Path.Combine(dirPath, "TestPackage_TestBasicPackageCreateSaveLoad_Generated1.sdpkg"); // Force the PackageId to be the same each time we run the test // Usually the PackageId is unique and generated each time we create a new project var project = new Package { FullPath = testGenerated1 }; project.AssetFolders.Clear(); project.AssetFolders.Add(new AssetFolder(".")); var session = new PackageSession(project); // Write the solution when saving session.SolutionPath = Path.Combine(dirPath, "TestPackage_TestBasicPackageCreateSaveLoad_Generated1.sln"); // Delete the solution before saving it if (File.Exists(session.SolutionPath)) { File.Delete(session.SolutionPath); } var result = new LoggerResult(); session.Save(result); Assert.False(result.HasErrors); // Reload the raw package and if UFile and UDirectory were saved relative var rawPackage = AssetFileSerializer.Load <Package>(testGenerated1).Asset; var rawSourceFolder = rawPackage.AssetFolders.FirstOrDefault(); Assert.NotNull(rawSourceFolder); Assert.Equal(".", (string)rawSourceFolder.Path); // Reload the package directly from the sdpkg var project2Result = PackageSession.Load(testGenerated1); AssertResult(project2Result); var project2 = project2Result.Session.LocalPackages.FirstOrDefault(); Assert.NotNull(project2); Assert.True(project2.AssetFolders.Count > 0); var sourceFolder = project.AssetFolders.First().Path; Assert.Equal(sourceFolder, project2.AssetFolders.First().Path); }
public void TestPackageLoadingWithAssets() { var basePath = Path.Combine(DirectoryTestBase, @"TestPackage"); var projectPath = Path.Combine(basePath, "TestPackageLoadingWithAssets.pdxpkg"); var sessionResult = PackageSession.Load(projectPath); AssertResult(sessionResult); var session = sessionResult.Session; var rootPackageId = new Guid("4102BF96-796D-4800-9983-9C227FAB7BBD"); var project = session.Packages.Find(rootPackageId); Assert.IsNotNull(project); Assert.AreEqual(3, project.Assets.Count, "Invalid number of assets loaded"); Assert.AreEqual(1, project.LocalDependencies.Count, "Expecting subproject"); Assert.AreNotEqual(Guid.Empty, project.Assets.First().Id); // Check for UPathRelativeTo var profile = project.Profiles.FirstOrDefault(); Assert.NotNull(profile); var folder = profile.AssetFolders.FirstOrDefault(); Assert.NotNull(folder); Assert.NotNull(folder.Path); Assert.NotNull(folder.Path.IsAbsolute); var import = folder.RawImports.FirstOrDefault(); Assert.NotNull(import); Assert.IsTrue(import.SourceDirectory != null && import.SourceDirectory.IsRelative); // Save project back to disk on a different location project.FullPath = Path.Combine(DirectoryTestBase, @"TestPackage2\TestPackage2.pdxpkg"); var subPackage = session.Packages.Find(Guid.Parse("281321F0-7664-4523-B1DC-3CFC26F80F77")); subPackage.FullPath = Path.Combine(DirectoryTestBase, @"TestPackage2\SubPackage\SubPackage.pdxpkg"); session.Save(); var project2Result = PackageSession.Load(DirectoryTestBase + @"TestPackage2\TestPackage2.pdxpkg"); AssertResult(project2Result); var project2 = project2Result.Session.Packages.Find(rootPackageId); Assert.IsNotNull(project2); Assert.AreEqual(3, project2.Assets.Count); }
private static int Main(string[] args) { Console.WriteLine(@"Bootstrapping: " + args[0]); var xenkoDir = Environment.GetEnvironmentVariable("SiliconStudioXenkoDir"); var xenkoPkgPath = UPath.Combine(xenkoDir, new UFile("Xenko.xkpkg")); var session = PackageSession.Load(xenkoPkgPath); var generator = TemplateSampleGenerator.Default; var logger = new LoggerResult(); var parameters = new SessionTemplateGeneratorParameters { Session = session.Session }; TemplateSampleGenerator.SetDontAskForPlatforms(parameters, true); TemplateSampleGenerator.SetPlatforms(parameters, AssetRegistry.SupportedPlatforms.ToList()); var outputPath = UPath.Combine(new UDirectory(xenkoDir), new UDirectory("samplesGenerated")); outputPath = UPath.Combine(outputPath, new UDirectory(args[0])); var xenkoTemplates = session.Session.Packages.First().Templates; parameters.Description = xenkoTemplates.First(x => x.Group.StartsWith("Samples") && x.Id == new Guid(args[1])); parameters.Name = args[0]; parameters.Namespace = args[0]; parameters.OutputDirectory = outputPath; parameters.Logger = logger; if (!generator.PrepareForRun(parameters)) { logger.Error("PrepareForRun returned false for the TemplateSampleGenerator"); } if (!generator.Run(parameters)) { logger.Error("Run returned false for the TemplateSampleGenerator"); } var updaterTemplate = xenkoTemplates.First(x => x.FullPath.ToString().EndsWith("UpdatePlatforms.xktpl")); parameters.Description = updaterTemplate; Console.WriteLine(logger.ToText()); return(logger.HasErrors ? 1 : 0); }
public void TestPackageLoadingWithAssets() { var basePath = Path.Combine(DirectoryTestBase, @"TestPackage"); var projectPath = Path.Combine(basePath, "TestPackageLoadingWithAssets.sdpkg"); var sessionResult = PackageSession.Load(projectPath); AssertResult(sessionResult); var session = sessionResult.Session; var project = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "TestPackageLoadingWithAssets"); Assert.NotNull(project); Assert.True(3 == project.Assets.Count, "Invalid number of assets loaded"); Assert.True(1 == project.Container.FlattenedDependencies.Count, "Expecting subproject"); Assert.NotEqual(AssetId.Empty, project.Assets.First().Id); // Check for UPathRelativeTo var folder = project.AssetFolders.FirstOrDefault(); Assert.NotNull(folder); Assert.NotNull(folder.Path); Assert.True(folder.Path.IsAbsolute); // Save project back to disk on a different location project.FullPath = Path.Combine(DirectoryTestBase, @"TestPackage2\TestPackage2.sdpkg"); var subPackage = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "SubPackage"); subPackage.FullPath = Path.Combine(DirectoryTestBase, @"TestPackage2\SubPackage\SubPackage.sdpkg"); var result = new LoggerResult(); session.Save(result); var project2Result = PackageSession.Load(DirectoryTestBase + @"TestPackage2\TestPackage2.sdpkg"); AssertResult(project2Result); var project2 = project2Result.Session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "TestPackage2"); Assert.NotNull(project2); Assert.Equal(3, project2.Assets.Count); }
private List <string> CollectShadersDirectories(string packagePath) { if (packagePath == null) { packagePath = PackageStore.Instance.DefaultPackage.FullPath; } var defaultLoad = PackageLoadParameters.Default(); defaultLoad.AutoCompileProjects = false; defaultLoad.AutoLoadTemporaryAssets = false; defaultLoad.ConvertUPathToAbsolute = false; defaultLoad.GenerateNewAssetIds = false; defaultLoad.LoadAssemblyReferences = false; var sessionResult = PackageSession.Load(packagePath, defaultLoad); if (sessionResult.HasErrors) { // TODO: Throw an error return(null); } var session = sessionResult.Session; var assetsPaths = new List <string>(); foreach (var package in session.Packages) { foreach (var profile in package.Profiles) { foreach (var folder in profile.AssetFolders) { var fullPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(packagePath), folder.Path)); assetsPaths.Add(fullPath); assetsPaths.AddRange(Directory.EnumerateDirectories(fullPath, "*.*", SearchOption.AllDirectories)); } } } return(assetsPaths); }
private List <string> CollectShadersDirectories(string packagePath) { if (packagePath == null) { packagePath = PackageStore.Instance.GetPackageFileName("Stride.Engine", new PackageVersionRange(new PackageVersion(StrideVersion.NuGetVersion))); } var defaultLoad = PackageLoadParameters.Default(); defaultLoad.AutoCompileProjects = false; defaultLoad.AutoLoadTemporaryAssets = false; defaultLoad.GenerateNewAssetIds = false; defaultLoad.LoadAssemblyReferences = false; var sessionResult = PackageSession.Load(packagePath, defaultLoad); if (sessionResult.HasErrors) { // TODO: Throw an error return(null); } var session = sessionResult.Session; var assetsPaths = new List <string>(); foreach (var package in session.Packages) { foreach (var assetFolder in package.AssetFolders) { var fullPath = assetFolder.Path.ToWindowsPath(); if (Directory.Exists(fullPath)) { assetsPaths.Add(fullPath); assetsPaths.AddRange(Directory.EnumerateDirectories(fullPath, "*.*", SearchOption.AllDirectories)); } } } return(assetsPaths); }
public async Task <PackageSessionResult> LoadProject(string path) { var viewUpdater = Services.GetService <IViewUpdater>(); PackageSessionResult sessionResult = await SetupResultProgress(viewUpdater, LoadProjectScope); using (var scope = new TimedScope(LoadProjectScope, TimedScope.Status.Failure)) { // Force PackageSession.Load to be executed on the thread pool // otherwise it would block execution and we want this process to be async await Task.Run(() => { PackageSession.Load(path, sessionResult); }).ConfigureAwait(false); PackageSession = sessionResult.Session; foreach (var pkg in PackageSession.LocalPackages) { pkg.UpdateAssemblyReferences(LoggingScope.Global($"{nameof(Session)}.{nameof(pkg.UpdateAssemblyReferences)}")); } if (!sessionResult.HasErrors) { scope.Result = TimedScope.Status.Success; } } // Create asset browser for package and add it to the viewmodel var browser = new AssetBrowserViewModel(PackageSession); await Services.GetService <ITabManager>().CreateToolTab(browser); EditorViewModel.LoadingStatus = null; await viewUpdater.UpdateView(); ProjectLoaded?.Invoke(sessionResult); return(sessionResult); }
public TestThumbnails() { // load assembly to register the assets extensions RuntimeHelpers.RunModuleConstructor(typeof(Asset).Module.ModuleHandle); var assembly = Assembly.Load("Stride.Assets.Presentation"); foreach (var module in assembly.Modules) { RuntimeHelpers.RunModuleConstructor(module.ModuleHandle); } // load the project var projectSessionResult = PackageSession.Load("..\\..\\sources\\tools\\Stride.Previewer.Tests\\Assets\\Assets.sdpkg"); projectSession = projectSessionResult.Session; //projectSession = PackageSession.Load(@"C:\Dev\sengokurun\SengokuRun\SengokuRun\GameAssets\SengokuRun.sdpkg"); // find an entity in the project //previewAsset = projectSession.FindAsset("mc00_entity"); // create the asset previewer and subscribe to the build progress events // TODO: desactivated //thumbnailService = new GameStudioPreviewService(projectSession, null, "..\\..\\sources\\tools\\Stride.Previewer.Tests\\obj", null).ThumbnailService; //thumbnailService.ThumbnailCompleted += PreviewerOnThumbnailBuilt; }
private BuildResultCode BuildMaster() { try { PackageSessionPublicHelper.FindAndSetMSBuildVersion(); } catch (Exception e) { var message = "Could not find a compatible version of MSBuild.\r\n\r\n" + "Check that you have a valid installation with the required workloads, or go to [www.visualstudio.com/downloads](https://www.visualstudio.com/downloads) to install a new one.\r\n\r\n" + e; builderOptions.Logger.Error(message); return(BuildResultCode.BuildError); } AssetCompilerContext context = null; PackageSession projectSession = null; try { var sessionLoadParameters = new PackageLoadParameters { AutoCompileProjects = !builderOptions.DisableAutoCompileProjects, ExtraCompileProperties = builderOptions.ExtraCompileProperties, RemoveUnloadableObjects = true, BuildConfiguration = builderOptions.ProjectConfiguration, }; // Loads the root Package var projectSessionResult = PackageSession.Load(builderOptions.PackageFile, sessionLoadParameters); projectSessionResult.CopyTo(builderOptions.Logger); if (projectSessionResult.HasErrors) { return(BuildResultCode.BuildError); } projectSession = projectSessionResult.Session; // Find loaded package (either xkpkg or csproj) -- otherwise fallback to first one var packageFile = (UFile)builderOptions.PackageFile; var package = projectSession.LocalPackages.FirstOrDefault(x => x.FullPath == packageFile || (x.Container is SolutionProject project && project.FullPath == packageFile)) ?? projectSession.LocalPackages.First(); // Setup variables var buildDirectory = builderOptions.BuildDirectory; var outputDirectory = builderOptions.OutputDirectory; // Process game settings asset var gameSettingsAsset = package.GetGameSettingsAsset(); if (gameSettingsAsset == null) { builderOptions.Logger.Warning($"Could not find game settings asset at location [{GameSettingsAsset.GameSettingsLocation}]. Use a Default One"); gameSettingsAsset = GameSettingsFactory.Create(); } // Create context context = new AssetCompilerContext { Platform = builderOptions.Platform, CompilationContext = typeof(AssetCompilationContext), BuildConfiguration = builderOptions.ProjectConfiguration, Package = package, }; // Command line properties foreach (var property in builderOptions.Properties) { context.OptionProperties.Add(property.Key, property.Value); } // Set current game settings context.SetGameSettingsAsset(gameSettingsAsset); // Builds the project var assetBuilder = new PackageCompiler(new RootPackageAssetEnumerator(package)); assetBuilder.AssetCompiled += RegisterBuildStepProcessedHandler; context.Properties.Set(BuildAssetNode.VisitRuntimeTypes, true); var assetBuildResult = assetBuilder.Prepare(context); assetBuildResult.CopyTo(builderOptions.Logger); if (assetBuildResult.HasErrors) { return(BuildResultCode.BuildError); } // Setup the remote process build var remoteBuilderHelper = new PackageBuilderRemoteHelper(projectSession.AssemblyContainer, builderOptions); var indexName = "index." + package.Meta.Name; // Add runtime identifier (if any) to avoid clash when building multiple at the same time (this happens when using ExtrasBuildEachRuntimeIdentifier feature of MSBuild.Sdk.Extras) if (builderOptions.Properties.TryGetValue("RuntimeIdentifier", out var runtimeIdentifier)) { indexName += $".{runtimeIdentifier}"; } // Create the builder builder = new Builder(builderOptions.Logger, buildDirectory, indexName) { ThreadCount = builderOptions.ThreadCount, TryExecuteRemote = remoteBuilderHelper.TryExecuteRemote }; builder.MonitorPipeNames.AddRange(builderOptions.MonitorPipeNames); // Add build steps generated by AssetBuilder builder.Root.Add(assetBuildResult.BuildSteps); // Run builder var result = builder.Run(Builder.Mode.Build); builder.WriteIndexFile(false); // Fill list of bundles var bundlePacker = new BundlePacker(); bundlePacker.Build(builderOptions.Logger, projectSession, indexName, outputDirectory, builder.DisableCompressionIds, context.GetCompilationMode() != CompilationMode.AppStore); return(result); } finally { builder?.Dispose(); // Dispose the session (in order to unload assemblies) projectSession?.Dispose(); context?.Dispose(); // Make sure that MSBuild doesn't hold anything else VSProjectHelper.Reset(); } }
private BuildResultCode BuildMaster() { // Only querying graphics platform, let's load package, print it and exit if (builderOptions.GetGraphicsPlatform) { return(BuildGetGraphicsPlatform()); } AssetCompilerContext context = null; PackageSession projectSession = null; try { // TODO handle solution file + package-id ? // When the current platform is not on windows, we need to make sure that all plugins are build, so we // setup auto-compile when loading the session var sessionLoadParameters = new PackageLoadParameters { AutoCompileProjects = builderOptions.Platform != PlatformType.Windows || !builderOptions.DisableAutoCompileProjects, ExtraCompileProperties = builderOptions.ExtraCompileProperties, }; // Loads the root Package var projectSessionResult = PackageSession.Load(builderOptions.PackageFile, sessionLoadParameters); if (projectSessionResult.HasErrors) { projectSessionResult.CopyTo(builderOptions.Logger); return(BuildResultCode.BuildError); } projectSession = projectSessionResult.Session; // Check build configuration var package = projectSession.LocalPackages.Last(); // Check build profile var sharedProfile = package.Profiles.FindSharedProfile(); var buildProfile = package.Profiles.FirstOrDefault(pair => pair.Name == builderOptions.BuildProfile); if (buildProfile == null) { builderOptions.Logger.Error("Unable to find profile [{0}] in package [{1}]", builderOptions.BuildProfile, package.FullPath); return(BuildResultCode.BuildError); } // Setup variables var buildDirectory = builderOptions.BuildDirectory; var outputDirectory = builderOptions.OutputDirectory; // Process game settings asset var gameSettingsAsset = package.GetGameSettingsAsset(); if (gameSettingsAsset == null) { builderOptions.Logger.Warning("Could not find game settings asset at location [{0}]. Use a Default One", GameSettingsAsset.GameSettingsLocation); gameSettingsAsset = GameSettingsFactory.Create(); } // Create context context = new AssetCompilerContext { Profile = builderOptions.BuildProfile, Platform = builderOptions.Platform, BuildConfiguration = builderOptions.ProjectConfiguration }; // Command line properties foreach (var property in builderOptions.Properties) { context.OptionProperties.Add(property.Key, property.Value); } // Set current game settings context.SetGameSettingsAsset(gameSettingsAsset); // Copy properties from shared profiles to context properties if (sharedProfile != null) { sharedProfile.Properties.CopyTo(context.PackageProperties, true); } // Copy properties from build profile buildProfile.Properties.CopyTo(context.PackageProperties, true); // Builds the project var assetBuilder = new PackageCompiler(new RootPackageAssetEnumerator(package)); assetBuilder.AssetCompiled += RegisterBuildStepProcessedHandler; var assetBuildResult = assetBuilder.Compile(context); assetBuildResult.CopyTo(builderOptions.Logger); if (assetBuildResult.HasErrors) { return(BuildResultCode.BuildError); } // Add specific steps to generate shaders // TODO: This doesn't really belong here, where should we move it? //assetBuildResult.BuildSteps.Add(new WaitBuildStep()); //assetBuildResult.BuildSteps.Add(new CompileDefaultSceneEffectCommand(context, package, assetBuildResult)); // Create the builder var indexName = "index." + builderOptions.BuildProfile; builder = new Builder(builderOptions.Logger, buildDirectory, builderOptions.BuildProfile, indexName) { ThreadCount = builderOptions.ThreadCount }; builder.MonitorPipeNames.AddRange(builderOptions.MonitorPipeNames); // Add build steps generated by AssetBuilder builder.Root.Add(assetBuildResult.BuildSteps); // Run builder var result = builder.Run(Builder.Mode.Build); builder.WriteIndexFile(false); // Fill list of bundles var bundlePacker = new BundlePacker(); bundlePacker.Build(builderOptions.Logger, projectSession, buildProfile, indexName, outputDirectory, builder.DisableCompressionIds); return(result); } finally { builder?.Dispose(); // Dispose the session (in order to unload assemblies) projectSession?.Dispose(); context?.Dispose(); } }
public void TestSplitTexture() { var sessionResult = PackageSession.Load("../../sources/engine/SiliconStudio.Paradox.Assets.Tests/SiliconStudio.Paradox.Assets.Tests.pdxpkg"); var session = sessionResult.Session; var materialItem = session.FindAsset("Cube/TestMaterial"); var material = (MaterialAsset)materialItem.Asset; var solver = new TextureAlphaComponentSplitter(session); var modifiedMaterial = solver.Run(material.Material, materialItem.Location.GetDirectory()); Assert.AreEqual(3, modifiedMaterial.Nodes.Count); Assert.AreEqual(1, modifiedMaterial.ColorNodes.Count); // test that the original structure of the material hasn't changed var originalRootNode = modifiedMaterial.Nodes[modifiedMaterial.ColorNodes.First().Value]; Assert.IsTrue(originalRootNode is MaterialBinaryNode); var originalBinaryRootNode = (MaterialBinaryNode)originalRootNode; Assert.AreEqual((int)MaterialBinaryOperand.Overlay, (int)originalBinaryRootNode.Operand); Assert.IsTrue(originalBinaryRootNode.LeftChild is MaterialBinaryNode); Assert.IsTrue(originalBinaryRootNode.RightChild is MaterialBinaryNode); var originalRootLeftChildNode = (MaterialBinaryNode)originalBinaryRootNode.LeftChild; var originalRootRightChildNode = (MaterialBinaryNode)originalBinaryRootNode.RightChild; Assert.AreEqual((int)MaterialBinaryOperand.Screen, (int)originalRootLeftChildNode.Operand); Assert.AreEqual((int)MaterialBinaryOperand.Saturate, (int)originalRootRightChildNode.Operand); Assert.IsTrue(originalRootLeftChildNode.LeftChild is MaterialReferenceNode); Assert.IsTrue(originalRootLeftChildNode.RightChild is MaterialReferenceNode); Assert.IsTrue(originalRootRightChildNode.RightChild is MaterialFloat4Node); var originalRootLeftLeftChildNode = (MaterialReferenceNode)originalRootLeftChildNode.LeftChild; var originalRootLeftRightChildNode = (MaterialReferenceNode)originalRootLeftChildNode.RightChild; var originalRootRightLeftChildNode = originalRootRightChildNode.LeftChild; var originalRootRightRightChildNode = (MaterialFloat4Node)originalRootRightChildNode.RightChild; Assert.AreEqual("diffuseFactor", originalRootLeftLeftChildNode.Name); Assert.AreEqual("diffuseTexture", originalRootLeftRightChildNode.Name); var rawUnreferencedRootLeftLeftChildNode = modifiedMaterial.Nodes["diffuseFactor"]; var rawUnreferencedRootLeftRightChildNode = modifiedMaterial.Nodes["diffuseTexture"]; Assert.IsTrue(rawUnreferencedRootLeftLeftChildNode is MaterialFloat4Node); var unreferencedRootLeftLeftChildNode = (MaterialFloat4Node)rawUnreferencedRootLeftLeftChildNode; var unreferencedRootLeftRightChildNode = rawUnreferencedRootLeftRightChildNode; Assert.AreEqual(new Vector4(0.1f, 0.2f, 0.3f, 0.4f), unreferencedRootLeftLeftChildNode.Value); Assert.AreEqual(new Vector4(1f, 2f, 3f, 4f), originalRootRightRightChildNode.Value); var originalTextureNodes = new List <MaterialTextureNode> { (MaterialTextureNode)((MaterialBinaryNode)((MaterialBinaryNode)material.Material.Nodes["diffuse"]).RightChild).LeftChild, (MaterialTextureNode)material.Material.Nodes["diffuseTexture"] }; var modifiedTextureNodes = new List <IMaterialNode> { originalRootRightLeftChildNode, unreferencedRootLeftRightChildNode }; // test that the old MaterialTextureReferences has been substituted for (int i = 0; i < originalTextureNodes.Count; i++) { var originalTextureNode = originalTextureNodes[i]; var modifiedTextureNode = modifiedTextureNodes[i]; Assert.IsTrue(modifiedTextureNode is MaterialShaderClassNode); var newShaderNode = (MaterialShaderClassNode)modifiedTextureNode; Assert.AreEqual("ComputeColorSubstituteAlphaWithColor", Path.GetFileNameWithoutExtension(newShaderNode.MixinReference.Location)); Assert.IsTrue(newShaderNode.CompositionNodes.ContainsKey("color1")); Assert.IsTrue(newShaderNode.CompositionNodes.ContainsKey("color2")); Assert.IsTrue(newShaderNode.CompositionNodes["color1"] is MaterialTextureNode); Assert.IsTrue(newShaderNode.CompositionNodes["color2"] is MaterialTextureNode); var leftNode = (MaterialTextureNode)newShaderNode.CompositionNodes["color1"]; var rightNode = (MaterialTextureNode)newShaderNode.CompositionNodes["color2"]; var textureNodes = new List <MaterialTextureNode> { leftNode, rightNode }; foreach (var textureNode in textureNodes) { Assert.AreEqual(originalTextureNode.Sampler.AddressModeU, textureNode.Sampler.AddressModeU); Assert.AreEqual(originalTextureNode.Sampler.AddressModeV, textureNode.Sampler.AddressModeV); Assert.AreEqual(originalTextureNode.Sampler.Filtering, textureNode.Sampler.Filtering); Assert.AreEqual(originalTextureNode.Offset, textureNode.Offset); Assert.AreEqual(originalTextureNode.Sampler.SamplerParameterKey, textureNode.Sampler.SamplerParameterKey); Assert.AreEqual(originalTextureNode.Scale, textureNode.Scale); Assert.AreEqual(originalTextureNode.TexcoordIndex, textureNode.TexcoordIndex); } Assert.AreEqual(originalTextureNode.Key, leftNode.Key); Assert.AreEqual(null, rightNode.Key); const string textureName = "cube_Untitled"; const string leftNodeSupposedLocation = "Cube/" + TextureAlphaComponentSplitter.SplittedTextureNamePrefix + textureName + TextureAlphaComponentSplitter.SplittedColorTextureNameSuffix; const string rightNodeSupposedLocation = "Cube/" + TextureAlphaComponentSplitter.SplittedTextureNamePrefix + textureName + TextureAlphaComponentSplitter.SplittedAlphaTextureNameSuffix; Assert.AreEqual(leftNodeSupposedLocation, leftNode.TextureName); Assert.AreEqual(rightNodeSupposedLocation, rightNode.TextureName); Assert.IsTrue(AssetManager.FileProvider.FileExists(leftNodeSupposedLocation)); Assert.IsTrue(AssetManager.FileProvider.FileExists(rightNodeSupposedLocation)); } }
private BuildResultCode BuildMaster() { // Only querying graphics platform, let's load package, print it and exit if (builderOptions.GetGraphicsPlatform) { return(BuildGetGraphicsPlatform()); } assetLogger = new RemoteLogForwarder(builderOptions.Logger, builderOptions.LogPipeNames); GlobalLogger.GlobalMessageLogged += assetLogger; try { // TODO handle solution file + package-id ? // When the current platform is not on windows, we need to make sure that all plugins are build, so we // setup auto-compile when loading the session var sessionLoadParameters = new PackageLoadParameters { AutoCompileProjects = builderOptions.Platform != PlatformType.Windows || builderOptions.ProjectConfiguration != "Debug", // Avoid compiling if Windows|Debug ExtraCompileProperties = builderOptions.ExtraCompileProperties, }; // Loads the root Package var projectSessionResult = PackageSession.Load(builderOptions.PackageFile, sessionLoadParameters); if (projectSessionResult.HasErrors) { projectSessionResult.CopyTo(builderOptions.Logger); return(BuildResultCode.BuildError); } var projectSession = projectSessionResult.Session; // Check build configuration var package = projectSession.LocalPackages.First(); // Check build profile var sharedProfile = package.Profiles.FindSharedProfile(); var buildProfile = package.Profiles.FirstOrDefault(pair => pair.Name == builderOptions.BuildProfile); if (buildProfile == null) { builderOptions.Logger.Error("Unable to find profile [{0}] in package [{1}]", builderOptions.BuildProfile, package.FullPath); return(BuildResultCode.BuildError); } // Setup variables var buildDirectory = builderOptions.BuildDirectory; var outputDirectory = builderOptions.OutputDirectory; // Builds the project var assetBuilder = new PackageCompiler(); assetBuilder.AssetCompiled += RegisterBuildStepProcessedHandler; // Create context var context = new AssetCompilerContext { Package = package, Platform = builderOptions.Platform }; // Copy properties from shared profiles to context properties if (sharedProfile != null) { sharedProfile.Properties.CopyTo(context.PackageProperties, true); } // Copy properties from build profile buildProfile.Properties.CopyTo(context.PackageProperties, true); var gameSettingsAsset = context.Package.GetGameSettingsAsset(); if (gameSettingsAsset == null) { builderOptions.Logger.Error("Could not find game settings asset at location [{0}]", GameSettingsAsset.GameSettingsLocation); return(BuildResultCode.BuildError); } context.SetGameSettingsAsset(gameSettingsAsset); var assetBuildResult = assetBuilder.Compile(context); assetBuildResult.CopyTo(builderOptions.Logger); if (assetBuildResult.HasErrors) { return(BuildResultCode.BuildError); } // Create the builder var indexName = "index." + builderOptions.BuildProfile; builder = new Builder(buildDirectory, builderOptions.BuildProfile, indexName, "InputHashes", builderOptions.Logger) { ThreadCount = builderOptions.ThreadCount }; builder.MonitorPipeNames.AddRange(builderOptions.MonitorPipeNames); // Add build steps generated by AssetBuilder builder.Root.Add(assetBuildResult.BuildSteps); // Run builder var result = builder.Run(Builder.Mode.Build); builder.WriteIndexFile(false); // Fill list of bundles var bundlePacker = new BundlePacker(); bundlePacker.Build(builderOptions.Logger, projectSession, buildProfile, indexName, outputDirectory, builder.DisableCompressionIds); return(result); } finally { if (builder != null) { builder.Dispose(); } // Flush and close logger GlobalLogger.GlobalMessageLogged -= assetLogger; assetLogger.Dispose(); } }
private BuildResultCode BuildMaster() { // Only querying graphics platform, let's load package, print it and exit if (builderOptions.GetGraphicsPlatform) { return(BuildGetGraphicsPlatform()); } AssetCompilerContext context = null; PackageSession projectSession = null; try { if (!PackageSessionPublicHelper.FindAndSetMSBuildVersion()) { var message = "Could not find a compatible version of MSBuild.\r\n\r\n" + "Check that you have a valid installation with the required workloads, or go to [www.visualstudio.com/downloads](https://www.visualstudio.com/downloads) to install a new one."; builderOptions.Logger.Error(message); return(BuildResultCode.BuildError); } var sessionLoadParameters = new PackageLoadParameters { AutoCompileProjects = !builderOptions.DisableAutoCompileProjects, ExtraCompileProperties = builderOptions.ExtraCompileProperties, RemoveUnloadableObjects = true, }; // Loads the root Package var projectSessionResult = PackageSession.Load(builderOptions.PackageFile, sessionLoadParameters); projectSessionResult.CopyTo(builderOptions.Logger); if (projectSessionResult.HasErrors) { return(BuildResultCode.BuildError); } projectSession = projectSessionResult.Session; // Check build configuration var package = projectSession.LocalPackages.Last(); // Check build profile var buildProfile = package.Profiles.FirstOrDefault(pair => pair.Name == builderOptions.BuildProfile); if (buildProfile == null) { builderOptions.Logger.Error($"Unable to find profile [{builderOptions.BuildProfile}] in package [{package.FullPath}]"); return(BuildResultCode.BuildError); } // Setup variables var buildDirectory = builderOptions.BuildDirectory; var outputDirectory = builderOptions.OutputDirectory; // Process game settings asset var gameSettingsAsset = package.GetGameSettingsAsset(); if (gameSettingsAsset == null) { builderOptions.Logger.Warning($"Could not find game settings asset at location [{GameSettingsAsset.GameSettingsLocation}]. Use a Default One"); gameSettingsAsset = GameSettingsFactory.Create(); } // Create context context = new AssetCompilerContext { Profile = builderOptions.BuildProfile, Platform = builderOptions.Platform, CompilationContext = typeof(AssetCompilationContext), BuildConfiguration = builderOptions.ProjectConfiguration }; // Command line properties foreach (var property in builderOptions.Properties) { context.OptionProperties.Add(property.Key, property.Value); } // Set current game settings context.SetGameSettingsAsset(gameSettingsAsset); // Builds the project var assetBuilder = new PackageCompiler(new RootPackageAssetEnumerator(package)); assetBuilder.AssetCompiled += RegisterBuildStepProcessedHandler; context.Properties.Set(BuildAssetNode.VisitRuntimeTypes, true); var assetBuildResult = assetBuilder.Prepare(context); assetBuildResult.CopyTo(builderOptions.Logger); if (assetBuildResult.HasErrors) { return(BuildResultCode.BuildError); } // Setup the remote process build var remoteBuilderHelper = new PackageBuilderRemoteHelper(projectSession.AssemblyContainer, builderOptions); // Create the builder var indexName = "index." + builderOptions.BuildProfile; builder = new Builder(builderOptions.Logger, buildDirectory, builderOptions.BuildProfile, indexName) { ThreadCount = builderOptions.ThreadCount, TryExecuteRemote = remoteBuilderHelper.TryExecuteRemote }; builder.MonitorPipeNames.AddRange(builderOptions.MonitorPipeNames); // Add build steps generated by AssetBuilder builder.Root.Add(assetBuildResult.BuildSteps); // Run builder var result = builder.Run(Builder.Mode.Build); builder.WriteIndexFile(false); // Fill list of bundles var bundlePacker = new BundlePacker(); bundlePacker.Build(builderOptions.Logger, projectSession, buildProfile, indexName, outputDirectory, builder.DisableCompressionIds, context.GetCompilationMode() != CompilationMode.AppStore); return(result); } finally { builder?.Dispose(); // Dispose the session (in order to unload assemblies) projectSession?.Dispose(); context?.Dispose(); // Make sure that MSBuild doesn't hold anything else VSProjectHelper.Reset(); } }
public void TestMovingAssets() { var basePath = Path.Combine(DirectoryTestBase, @"TestPackage"); var projectPath = Path.Combine(basePath, "TestPackageLoadingWithAssets.xkpkg"); var rootPackageId = new Guid("4102BF96-796D-4800-9983-9C227FAB7BBD"); var testAssetId = new Guid("C2D80EF9-2160-43B2-9FEE-A19A903A0BE0"); // Load the project from the original location var sessionResult1 = PackageSession.Load(projectPath); { AssertResult(sessionResult1); var session = sessionResult1.Session; var project = session.Packages.Find(rootPackageId); Assert.IsNotNull(project); Assert.AreEqual(3, project.Assets.Count, "Invalid number of assets loaded"); // Find the second asset that was referencing the changed asset var testAssetItem = session.FindAsset(testAssetId); Assert.NotNull(testAssetItem); var testAsset = (AssetObjectTest)testAssetItem.Asset; Assert.AreEqual(new UFile(Path.Combine(basePath, "SubFolder/TestAsset.xktest")), testAsset.RawAsset); // First save a copy of the project to TestPackageMovingAssets1 project.FullPath = Path.Combine(DirectoryTestBase, @"TestPackageMovingAssets1\TestPackage2.xkpkg"); var subPackage = session.Packages.Find(Guid.Parse("281321F0-7664-4523-B1DC-3CFC26F80F77")); subPackage.FullPath = Path.Combine(DirectoryTestBase, @"TestPackageMovingAssets1\SubPackage\SubPackage.xkpkg"); session.Save(); } // Reload the project from the location TestPackageMovingAssets1 var sessionResult2 = PackageSession.Load(DirectoryTestBase + @"TestPackageMovingAssets1\TestPackage2.xkpkg"); { AssertResult(sessionResult2); var session = sessionResult2.Session; var project = session.Packages.Find(rootPackageId); Assert.IsNotNull(project); Assert.AreEqual(3, project.Assets.Count, "Invalid number of assets loaded"); // Move asset into a different directory var assetItem = project.Assets.Find(new Guid("28D0DE9C-8913-41B1-B50E-848DD8A7AF65")); Assert.NotNull(assetItem); project.Assets.Remove(assetItem); var newAssetItem = new AssetItem("subTest/TestAsset2", assetItem.Asset); project.Assets.Add(newAssetItem); // Save the whole project to a different location project.FullPath = Path.Combine(DirectoryTestBase, @"TestPackageMovingAssets2\TestPackage2.xkpkg"); var subPackage = session.Packages.Find(Guid.Parse("281321F0-7664-4523-B1DC-3CFC26F80F77")); subPackage.FullPath = Path.Combine(DirectoryTestBase, @"TestPackageMovingAssets2\SubPackage\SubPackage.xkpkg"); session.Save(); } // Reload the project from location TestPackageMovingAssets2 var sessionResult3 = PackageSession.Load(DirectoryTestBase + @"TestPackageMovingAssets2\TestPackage2.xkpkg"); { AssertResult(sessionResult3); var session = sessionResult3.Session; var project = session.Packages.Find(rootPackageId); Assert.IsNotNull(project); Assert.AreEqual(3, project.Assets.Count, "Invalid number of assets loaded"); // Find the second asset that was referencing the changed asset var assetItemChanged = session.FindAsset(testAssetId); Assert.NotNull(assetItemChanged); // Check that references were correctly updated var assetChanged = (AssetObjectTest)assetItemChanged.Asset; Assert.AreEqual(new UFile(Path.Combine(Environment.CurrentDirectory, DirectoryTestBase) + "/TestPackage/SubFolder/TestAsset.xktest"), assetChanged.RawAsset); var text = File.ReadAllText(assetItemChanged.FullPath); Assert.True(text.Contains("../../TestPackage/SubFolder/TestAsset.xktest")); Assert.AreEqual("subTest/TestAsset2", assetChanged.Reference.Location); } }
public void TestMovingAssets() { var basePath = Path.Combine(DirectoryTestBase, @"TestPackage"); var projectPath = Path.Combine(basePath, "TestPackageLoadingWithAssets.sdpkg"); var testAssetId = new AssetId("C2D80EF9-2160-43B2-9FEE-A19A903A0BE0"); // Load the project from the original location var sessionResult1 = PackageSession.Load(projectPath); { AssertResult(sessionResult1); var session = sessionResult1.Session; var project = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "TestPackageLoadingWithAssets"); Assert.NotNull(project); Assert.True(3 == project.Assets.Count, "Invalid number of assets loaded"); // Find the second asset that was referencing the changed asset var testAssetItem = session.FindAsset(testAssetId); Assert.NotNull(testAssetItem); var testAsset = (AssetObjectTest)testAssetItem.Asset; Assert.Equal(new UFile(Path.Combine(basePath, "SubFolder/TestAsset.sdtest")), testAsset.RawAsset); // First save a copy of the project to TestPackageMovingAssets1 project.FullPath = Path.Combine(DirectoryTestBase, @"TestPackageMovingAssets1\TestPackage2.sdpkg"); var subPackage = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "SubPackage"); subPackage.FullPath = Path.Combine(DirectoryTestBase, @"TestPackageMovingAssets1\SubPackage\SubPackage.sdpkg"); var result = new LoggerResult(); session.Save(result); } // Reload the project from the location TestPackageMovingAssets1 var sessionResult2 = PackageSession.Load(DirectoryTestBase + @"TestPackageMovingAssets1\TestPackage2.sdpkg"); { AssertResult(sessionResult2); var session = sessionResult2.Session; var project = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "TestPackage2"); Assert.NotNull(project); Assert.True(3 == project.Assets.Count, "Invalid number of assets loaded"); // Move asset into a different directory var assetItem = project.Assets.Find(new AssetId("28D0DE9C-8913-41B1-B50E-848DD8A7AF65")); Assert.NotNull(assetItem); project.Assets.Remove(assetItem); var newAssetItem = new AssetItem("subTest/TestAsset2", assetItem.Asset); project.Assets.Add(newAssetItem); // Save the whole project to a different location project.FullPath = Path.Combine(DirectoryTestBase, @"TestPackageMovingAssets2\TestPackage2.sdpkg"); var subPackage = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "TestPackage2"); subPackage.FullPath = Path.Combine(DirectoryTestBase, @"TestPackageMovingAssets2\SubPackage\SubPackage.sdpkg"); var result = new LoggerResult(); session.Save(result); } // Reload the project from location TestPackageMovingAssets2 var sessionResult3 = PackageSession.Load(DirectoryTestBase + @"TestPackageMovingAssets2\TestPackage2.sdpkg"); { AssertResult(sessionResult3); var session = sessionResult3.Session; var project = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "TestPackage2"); Assert.NotNull(project); Assert.True(3 == project.Assets.Count, "Invalid number of assets loaded"); // Find the second asset that was referencing the changed asset var assetItemChanged = session.FindAsset(testAssetId); Assert.NotNull(assetItemChanged); // Check that references were correctly updated var assetChanged = (AssetObjectTest)assetItemChanged.Asset; Assert.Equal(new UFile(Path.Combine(Environment.CurrentDirectory, DirectoryTestBase) + "/TestPackage/SubFolder/TestAsset.sdtest"), assetChanged.RawAsset); var text = File.ReadAllText(assetItemChanged.FullPath); Assert.Contains("../../TestPackage/SubFolder/TestAsset.sdtest", text); Assert.Equal("subTest/TestAsset2", assetChanged.Reference.Location); } }
private BuildResultCode BuildMaster() { // Only querying graphics platform, let's load package, print it and exit if (builderOptions.GetGraphicsPlatform) { return(BuildGetGraphicsPlatform()); } AssetCompilerContext context = null; PackageSession projectSession = null; try { // When the current platform is not on windows, we need to make sure that all plugins are build, so we // setup auto-compile when loading the session var sessionLoadParameters = new PackageLoadParameters { AutoCompileProjects = builderOptions.Platform != PlatformType.Windows || !builderOptions.DisableAutoCompileProjects, ExtraCompileProperties = builderOptions.ExtraCompileProperties, RemoveUnloadableObjects = true, }; // Loads the root Package var projectSessionResult = PackageSession.Load(builderOptions.PackageFile, sessionLoadParameters); projectSessionResult.CopyTo(builderOptions.Logger); if (projectSessionResult.HasErrors) { return(BuildResultCode.BuildError); } projectSession = projectSessionResult.Session; // Check build configuration var package = projectSession.LocalPackages.Last(); // Check build profile var buildProfile = package.Profiles.FirstOrDefault(pair => pair.Name == builderOptions.BuildProfile); if (buildProfile == null) { builderOptions.Logger.Error($"Unable to find profile [{builderOptions.BuildProfile}] in package [{package.FullPath}]"); return(BuildResultCode.BuildError); } // Setup variables var buildDirectory = builderOptions.BuildDirectory; var outputDirectory = builderOptions.OutputDirectory; // Process game settings asset var gameSettingsAsset = package.GetGameSettingsAsset(); if (gameSettingsAsset == null) { builderOptions.Logger.Warning($"Could not find game settings asset at location [{GameSettingsAsset.GameSettingsLocation}]. Use a Default One"); gameSettingsAsset = GameSettingsFactory.Create(); } // Create context context = new AssetCompilerContext { Profile = builderOptions.BuildProfile, Platform = builderOptions.Platform, CompilationContext = typeof(AssetCompilationContext), BuildConfiguration = builderOptions.ProjectConfiguration }; // Command line properties foreach (var property in builderOptions.Properties) { context.OptionProperties.Add(property.Key, property.Value); } // Set current game settings context.SetGameSettingsAsset(gameSettingsAsset); // Builds the project var assetBuilder = new PackageCompiler(new RootPackageAssetEnumerator(package)); assetBuilder.AssetCompiled += RegisterBuildStepProcessedHandler; context.Properties.Set(BuildAssetNode.VisitRuntimeTypes, true); var assetBuildResult = assetBuilder.Prepare(context); assetBuildResult.CopyTo(builderOptions.Logger); if (assetBuildResult.HasErrors) { return(BuildResultCode.BuildError); } // Create the builder var indexName = "index." + builderOptions.BuildProfile; builder = new Builder(builderOptions.Logger, buildDirectory, builderOptions.BuildProfile, indexName) { ThreadCount = builderOptions.ThreadCount }; // Note: try to get exec server if it exists, otherwise use CompilerApp.exe builder.SlaveBuilderPath = (string)AppDomain.CurrentDomain.GetData("RealEntryAssemblyFile") ?? typeof(PackageBuilder).Assembly.Location; builder.MonitorPipeNames.AddRange(builderOptions.MonitorPipeNames); // Add build steps generated by AssetBuilder builder.Root.Add(assetBuildResult.BuildSteps); // Run builder var result = builder.Run(Builder.Mode.Build); builder.WriteIndexFile(false); // Fill list of bundles var bundlePacker = new BundlePacker(); bundlePacker.Build(builderOptions.Logger, projectSession, buildProfile, indexName, outputDirectory, builder.DisableCompressionIds, context.GetCompilationMode() != CompilationMode.AppStore); return(result); } finally { builder?.Dispose(); // Dispose the session (in order to unload assemblies) projectSession?.Dispose(); context?.Dispose(); } }
private BuildResultCode BuildMaster() { assetLogger = new RemoteLogForwarder(builderOptions.Logger, builderOptions.LogPipeNames); GlobalLogger.GlobalMessageLogged += assetLogger; // TODO handle solution file + package-id ? // When the current platform is not on windows, we need to make sure that all plugins are build, so we // setup auto-compile when loading the session var sessionLoadParameters = new PackageLoadParameters() { AutoCompileProjects = builderOptions.Platform != PlatformType.Windows || builderOptions.ProjectConfiguration != "Debug", // Avoid compiling if Windows|Debug ExtraCompileProperties = builderOptions.ExtraCompileProperties, }; // Loads the root Package var projectSessionResult = PackageSession.Load(builderOptions.PackageFile, sessionLoadParameters); if (projectSessionResult.HasErrors) { projectSessionResult.CopyTo(builderOptions.Logger); return(BuildResultCode.BuildError); } var projectSession = projectSessionResult.Session; // Check build configuration var package = projectSession.LocalPackages.First(); // Check build profile var buildProfile = package.Profiles.FirstOrDefault(pair => pair.Name == builderOptions.BuildProfile); if (buildProfile == null) { builderOptions.Logger.Error("Unable to find profile [{0}] in package [{1}]", builderOptions.BuildProfile, package.FullPath); return(BuildResultCode.BuildError); } // Setup variables var buildDirectory = builderOptions.BuildDirectory; var outputDirectory = builderOptions.OutputDirectory; // Builds the project var assetBuilder = new PackageAssetsCompiler(projectSession); assetBuilder.AssetCompiled += RegisterBuildStepProcessedHandler; // Create context var context = new AssetCompilerContext { Package = package, Platform = builderOptions.Platform }; // If a build profile is available, output the properties context.Properties.Set(SiliconStudio.Paradox.Assets.ParadoxConfig.GraphicsPlatform, builderOptions.GraphicsPlatform.HasValue ? builderOptions.GraphicsPlatform.Value : builderOptions.GetDefaultGraphicsPlatform()); foreach (var propertyValue in buildProfile.Properties) { context.Properties.Set(propertyValue.Key, propertyValue.Value); } var assetBuildResult = assetBuilder.Compile(context); assetBuildResult.CopyTo(builderOptions.Logger); if (assetBuildResult.HasErrors) { return(BuildResultCode.BuildError); } // Create the builder var indexName = "index." + builderOptions.BuildProfile; builder = new Builder(buildDirectory, builderOptions.BuildProfile, indexName, "InputHashes", builderOptions.Logger) { ThreadCount = builderOptions.ThreadCount }; builder.MonitorPipeNames.AddRange(builderOptions.MonitorPipeNames); // Add build steps generated by AssetBuilder builder.Root.Add(assetBuildResult.BuildSteps); // Run builder var result = builder.Run(Builder.Mode.Build); builder.WriteIndexFile(false); // Fill list of bundles var bundlePacker = new BundlePacker(); bundlePacker.Build(builderOptions.Logger, projectSession, buildProfile, indexName, outputDirectory, builder.DisableCompressionIds); // Flush and close logger GlobalLogger.GlobalMessageLogged -= assetLogger; assetLogger.Dispose(); return(result); }
public void TestBasicPackageCreateSaveLoad() { PackageSessionPublicHelper.FindAndSetMSBuildVersion(); var dirPath = DirectoryTestBase + @"TestBasicPackageCreateSaveLoad"; string testGenerated1 = Path.Combine(dirPath, "TestPackage_TestBasicPackageCreateSaveLoad_Generated1.xkpkg"); string testGenerated2 = Path.Combine(dirPath, "TestPackage_TestBasicPackageCreateSaveLoad_Generated2.xkpkg"); string referenceFilePath = Path.Combine(dirPath, "TestPackage_TestBasicPackageCreateSaveLoad_Reference.xkpkg"); // Force the PackageId to be the same each time we run the test // Usually the PackageId is unique and generated each time we create a new project var project = new Package { Id = Guid.Empty, FullPath = testGenerated1 }; var sharedProfile = new PackageProfile("Shared", new AssetFolder(".")); project.Profiles.Add(sharedProfile); var projectReference = new ProjectReference(Guid.Empty, Path.Combine(dirPath, "test.csproj"), ProjectType.Executable); sharedProfile.ProjectReferences.Add(projectReference); var session = new PackageSession(project); // Write the solution when saving session.SolutionPath = Path.Combine(dirPath, "TestPackage_TestBasicPackageCreateSaveLoad_Generated1.sln"); // Delete the solution before saving it if (File.Exists(session.SolutionPath)) { File.Delete(session.SolutionPath); } var result = new LoggerResult(); session.Save(result); Assert.False(result.HasErrors); // Reload the raw package and if UFile and UDirectory were saved relative var rawPackage = AssetFileSerializer.Load <Package>(testGenerated1).Asset; var rawPackageSharedProfile = rawPackage.Profiles.FirstOrDefault(); Assert.NotNull(rawPackageSharedProfile); var rawSourceFolder = rawPackage.Profiles.First().AssetFolders.FirstOrDefault(); Assert.NotNull(rawSourceFolder); Assert.Equal(".", (string)rawSourceFolder.Path); Assert.Equal("test.csproj", (string)rawPackageSharedProfile.ProjectReferences[0].Location); // Reload the package directly from the xkpkg var project2Result = PackageSession.Load(testGenerated1); AssertResult(project2Result); var project2 = project2Result.Session.LocalPackages.FirstOrDefault(); Assert.NotNull(project2); Assert.Equal(project.Id, project2.Id); Assert.True(project2.Profiles.Count > 0); Assert.True(project2.Profiles.First().AssetFolders.Count > 0); Assert.Equal(project2, project2Result.Session.CurrentPackage); // Check that the current package is setup when loading a single package var sourceFolder = project.Profiles.First().AssetFolders.First().Path; Assert.Equal(sourceFolder, project2.Profiles.First().AssetFolders.First().Path); // Reload the package from the sln var sessionResult = PackageSession.Load(session.SolutionPath); Assert.False(sessionResult.HasErrors); var sessionReload = sessionResult.Session; Assert.Equal(1, sessionReload.LocalPackages.Count()); Assert.Equal(project.Id, sessionReload.LocalPackages.First().Id); Assert.Equal(1, sessionReload.LocalPackages.First().Profiles.Count); var sharedProfileReload = sessionReload.LocalPackages.First().Profiles.First(); Assert.Equal(1, sharedProfileReload.ProjectReferences.Count); Assert.Equal(projectReference, sharedProfileReload.ProjectReferences[0]); }