Example #1
0
        public static int Main(string[] args)
        {
            if (!TryParseArgs(args, out var generatorOptions))
            {
                return(1);
            }

            var result = new ResXGeneratorResult();

            ResXFileCodeGenerator.GenerateFile(generatorOptions, result).GetAwaiter().GetResult();

            var exitCode = (result.Success || result.SuccessWithWarnings) ? 0 : 1;

            if (result.UnhandledException != null)
            {
                Console.Error.WriteLine(result.UnhandledException.Message);
                Console.Error.WriteLine(result.UnhandledException.StackTrace);
            }

            foreach (CompilerError error in result.Errors)
            {
                Console.Error.WriteLine(error);
            }

            return(exitCode);
        }
Example #2
0
        public async Task BuildDotNetCoreProjectAfterGeneratingResources(string projectName)
        {
            FilePath solFile = Util.GetSampleProject("DotNetCoreResources", "DotNetCoreResources.sln");

            var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            var p = (DotNetProject)sol.Items.FirstOrDefault(item => item.Name == projectName);

            p.RequiresMicrosoftBuild = true;

            var resourceFile = p.Files.FirstOrDefault(f => f.FilePath.FileName == "Resources.resx");

            var customToolResult = new SingleFileCustomToolResult();
            await ResXFileCodeGenerator.GenerateFile(resourceFile, customToolResult, true);

            Assert.IsTrue(customToolResult.Success);

            // Running a restore for a .NET Core project can take a long time if
            // no packages are cached. So instead we just check the generated resource file.
            //var res = await p.RunTarget (Util.GetMonitor (), "Restore", ConfigurationSelector.Default);
            //Assert.AreEqual (0, res.BuildResult.Errors.Count);

            //res = await p.RunTarget (Util.GetMonitor (), "Build", ConfigurationSelector.Default);
            //Assert.AreEqual (0, res.BuildResult.Errors.Count);

            var generatedResourceFile = resourceFile.FilePath.ChangeExtension(".Designer.cs");

            bool foundLine = false;

            foreach (string line in File.ReadAllLines(generatedResourceFile))
            {
                if (line.Contains("typeof"))
                {
                    string lineWithoutSpaces = line.Replace(" ", "");
                    foundLine = lineWithoutSpaces.EndsWith("typeof(Resources).GetTypeInfo().Assembly);", StringComparison.Ordinal);
                    break;
                }
            }

            Assert.IsTrue(foundLine);

            sol.Dispose();
        }