public override void Initialize() { base.Initialize(); TypeFactory = new TypeDescriptorFactory(); var assetDesc = TypeFactory.Find(typeof(TestAssetUpdate)); memberMyClass = assetDesc.Members.FirstOrDefault(member => member.Name == "MyClass"); if (session != null) { session.Dispose(); dependencyManager.Dispose(); } package = new Package(); session = new PackageSession(package); dependencyManager = new AssetDependencyManager(session); assetUpdater = new AssetUpdater(dependencyManager); }
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(); } }
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(); } }
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(); } }