microsoft/MSBuildLocator

How To Build Release

Gao996 opened this issue · 4 comments

It seems that all builds are debug versions, how to do something like this
dotnet msbuild /p:Configuration=Release
Generate release version

dotnet msbuild --configuration Release worked for me.

What if you use code

public void MethodThatDoesNotDirectlyCallMSBuild()
        {
            MSBuildLocator.RegisterDefaults();
            Build();
        }

        private static void Build()
        {
            var p = new BuildParameters
            {
                MaxNodeCount = 4,
                Loggers = new ILogger[] { new Microsoft.Build.Logging.ConsoleLogger(LoggerVerbosity.Normal) },
            };

            var req = new BuildRequestData(BuildPath,
                new Dictionary<string, string>(),
                null,
                new[] { "Build" },
                null,
                BuildRequestDataFlags.None);

            var result = BuildManager.DefaultBuildManager.Build(p, req);

            if (result.OverallResult.Equals(BuildResultCode.Failure))
            {
                throw new System.Exception();
            }
        }

If setting the parameters like this will generate an empty Release folder, the build will still fail

var req = new BuildRequestData(BuildPath,
                new Dictionary<string, string>() { { "configuration","Release"} },
                null,
                new[] { "Build" },
                null,
                BuildRequestDataFlags.None);

When I use vs to generate once, these seem to work well, is the last successful version automatically generated?