public static void DrawBuildButtons(this MSBuildProjectReference msBuildProjectReference)
        {
            using (new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button("Build"))
                {
                    MSBuildProjectBuilder.BuildProject(msBuildProjectReference);
                }

                if (GUILayout.Button("Rebuild"))
                {
                    MSBuildProjectBuilder.BuildProject(msBuildProjectReference, MSBuildProjectBuilder.RebuildTargetArgument);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an in-memory instance that can resolve the full path to the MSBuild project.
        /// </summary>
        /// <param name="assetRelativePath">The path to the <see cref="MSBuildProjectReference"/> asset.</param>
        /// <param name="buildEngine">The MSBuild build engine that should be used to build the referenced project.</param>
        /// <param name="autoBuild">True to enable auto build of the referenced project.</param>
        /// <param name="profiles">The set of profiles used to configure different build options.</param>
        /// <returns>An <see cref="MSBuildProjectReference"/> instance.</returns>
        /// <remarks>
        /// This is useful for creating and passing transient <see cref="MSBuildProjectReference"/> instances to <see cref="MSBuildProjectBuilder"/> when they don't exist in the <see cref="AssetDatabase"/>.
        /// </remarks>
        public static MSBuildProjectReference FromMSBuildProject(string assetRelativePath, BuildEngine buildEngine = BuildEngine.DotNet, bool autoBuild = true, IEnumerable <MSBuildBuildProfile> profiles = null)
        {
            MSBuildProjectReference msBuildProjectReference = ScriptableObject.CreateInstance <MSBuildProjectReference>();

            msBuildProjectReference.assetRelativePath = assetRelativePath;
            msBuildProjectReference.projectPath       = Path.GetFileName(assetRelativePath);
            msBuildProjectReference.buildEngine       = buildEngine;

            if (profiles != null && profiles.Any())
            {
                msBuildProjectReference.profiles = profiles.ToArray();
            }
            else if (Path.GetFileNameWithoutExtension(assetRelativePath).EndsWith(".msb4u") && !Path.GetFileName(assetRelativePath).EndsWith("Dependencies.msb4u.csproj"))
            {
                msBuildProjectReference.profiles = null;
            }

            return(msBuildProjectReference);
        }
Exemplo n.º 3
0
 public static void DrawBuildButtons(this MSBuildProjectReference msBuildProjectReference)
 {
     using (new EditorGUILayout.HorizontalScope())
     {
         if (!msBuildProjectReference.Profiles.Any())
         {
             EditorGUILayout.HelpBox($"Define profiles below.", MessageType.Error);
         }
         else
         {
             foreach (var profile in msBuildProjectReference.Profiles)
             {
                 if (GUILayout.Button(profile.name))
                 {
                     MSBuildProjectBuilder.BuildProject(msBuildProjectReference, profile.name);
                 }
             }
         }
     }
 }
        public override void OnImportAsset(AssetImportContext context)
        {
            var msBuildProjectReference = MSBuildProjectReference.FromMSBuildProject(context.assetPath, this.buildEngine);

            context.AddObjectToAsset(Path.GetFileNameWithoutExtension(context.assetPath), msBuildProjectReference);
            context.SetMainObject(msBuildProjectReference);

            // Automatically build this project if the import is happening after the Unity project has been opened.
            // If the import is happening as part of loading the project, then the generated asset will automatically be built by MSBuildProjectBuilder.
            if (EditorAnalyticsSessionInfo.elapsedTime != 0)
            {
                try
                {
                    msBuildProjectReference.BuildProject();
                }
                catch (OperationCanceledException)
                {
                    Debug.LogWarning($"Canceled building {msBuildProjectReference.ProjectPath}.");
                }
            }
        }