/// <summary> /// Executes the task. /// </summary> /// <returns></returns> public override bool Execute() { if (this.BuildEngine != null) { Logger = new LogWrapper(Log, GetType().Name); } else { Logger ??= new MockTaskLogger(GetType().Name); } try { var manifest = MakeManifest(); manifest.Validate(RequiresBsipa); WriteManifest(manifest, TargetPath); BasePluginVersion = Util.StripVersionLabel(manifest.Version); PluginVersion = manifest.Version; return(true); } catch (ManifestValidationException ex) { // Generated manifest not valid. Logger.LogErrorFromException(ex); } catch (ArgumentException ex) { // Base manifest specified but doesn't exist. Logger.LogErrorFromException(ex); } catch (IOException ex) { // Base JSON read failed or write failed. Logger.LogErrorFromException(ex); } catch (Exception ex) { Logger.LogErrorFromException(ex); } return(false); }
/// <summary> /// Executes the task. /// </summary> /// <returns>true if successful</returns> public override bool Execute() { string errorCode = null; LogMessageLevel errorLevel = FailOnError ? LogMessageLevel.Error : LogMessageLevel.Warning; AssemblyInfoData asmInfo = default; string assemblyInfoPath = null; AssemblyVersion = MessageCodes.ErrorString; if (this.BuildEngine != null) { Logger = new LogWrapper(Log); } else { Logger = new MockTaskLogger(); } try { string assemblyFileMsg = ""; if (string.IsNullOrWhiteSpace(AssemblyInfoPath)) { assemblyInfoPath = Path.Combine("Properties", "AssemblyInfo.cs"); } else { assemblyInfoPath = AssemblyInfoPath; } try { asmInfo = ParseAssembly(assemblyInfoPath, FailOnError); AssemblyVersion = asmInfo.AssemblyVersion; } catch (FileNotFoundException ex) { if (FailOnError) { errorCode = MessageCodes.GetAssemblyInfo.AssemblyInfoNotFound; throw; } else { Logger.LogErrorFromException(ex); } } assemblyFileMsg = " in " + assemblyInfoPath; if (AssemblyVersion == null || AssemblyVersion == ErrorString || AssemblyVersion.Length == 0) { Logger.LogError("AssemblyVersion could not be determined."); return(false); } return(true); } catch (ParsingException ex) { if (string.IsNullOrEmpty(errorCode)) { errorCode = MessageCodes.GetAssemblyInfo.GeneralFailure; } if (BuildEngine != null) { int line = BuildEngine.LineNumberOfTaskNode; int column = BuildEngine.ColumnNumberOfTaskNode; Logger.LogError(null, errorCode, null, BuildEngine.ProjectFileOfTaskNode, line, column, line, column, ex.Message); } else { Logger.LogError(null, errorCode, null, null, ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber, ex.Message); } return(false); } catch (Exception ex) { if (string.IsNullOrEmpty(errorCode)) { errorCode = MessageCodes.GetAssemblyInfo.GeneralFailure; } if (BuildEngine != null) { int line = BuildEngine.LineNumberOfTaskNode; int column = BuildEngine.ColumnNumberOfTaskNode; Logger.LogError(null, errorCode, null, BuildEngine.ProjectFileOfTaskNode, line, column, line, column, $"Error in {GetType().Name}: {ex.Message}"); } else { Logger.LogError(null, errorCode, null, null, 0, 0, 0, 0, $"Error in {GetType().Name}: {ex.Message}"); } return(false); } }