Ejemplo n.º 1
0
        public override bool Execute()
        {
            bool success = true;

            Log.LogMessage(MessageImportance.Normal, "Generating assembly attributes for CSS files");
            if (XamlFiles == null)
            {
                Log.LogMessage(MessageImportance.Low, "Skipping CssG");
                return(true);
            }

            foreach (var xamlFile in XamlFiles)
            {
                var outputFile = Path.Combine(OutputPath, $"{xamlFile.GetMetadata("TargetPath")}.g.cs");
                var generator  = new CssGenerator(xamlFile, Language, AssemblyName, outputFile, Log);
                try {
                    if (generator.Execute())
                    {
                        _generatedCodeFiles.Add(new TaskItem(Microsoft.Build.Evaluation.ProjectCollection.Escape(outputFile)));
                    }
                }
                catch (XmlException xe) {
                    Log.LogError(null, null, null, xamlFile.ItemSpec, xe.LineNumber, xe.LinePosition, 0, 0, xe.Message, xe.HelpLink, xe.Source);

                    success = false;
                }
                catch (Exception e) {
                    Log.LogError(null, null, null, xamlFile.ItemSpec, 0, 0, 0, 0, e.Message, e.HelpLink, e.Source);
                    success = false;
                }
            }

            return(success);
        }
Ejemplo n.º 2
0
        public override bool Execute()
        {
            bool success = true;

            Log.LogMessage(MessageImportance.Normal, "Generating assembly attributes for CSS files");
            if (CSSFiles == null || OutputFiles == null)
            {
                Log.LogMessage(MessageImportance.Low, "Skipping CssG");
                return(true);
            }

            if (CSSFiles.Length != OutputFiles.Length)
            {
                Log.LogError("\"{2}\" refers to {0} item(s), and \"{3}\" refers to {1} item(s). They must have the same number of items.", CSSFiles.Length, OutputFiles.Length, "CSSFiles", "OutputFiles");
                return(false);
            }

            for (var i = 0; i < CSSFiles.Length; i++)
            {
                var cssFile    = CSSFiles[i];
                var outputFile = OutputFiles[i].ItemSpec;

                var generator = new CssGenerator(cssFile, Language, AssemblyName, outputFile, Log);
                try
                {
                    if (!generator.Execute())
                    {
                        //If Execute() fails, the file still needs to exist because it is added to the <Compile/> ItemGroup
                        File.WriteAllText(outputFile, string.Empty);
                    }
                }
                catch (XmlException xe)
                {
                    Log.LogError(null, null, null, cssFile.ItemSpec, xe.LineNumber, xe.LinePosition, 0, 0, xe.Message, xe.HelpLink, xe.Source);

                    success = false;
                }
                catch (Exception e)
                {
                    Log.LogError(null, null, null, cssFile.ItemSpec, 0, 0, 0, 0, e.Message, e.HelpLink, e.Source);
                    success = false;
                }
            }

            return(success);
        }