Repository: dotnet/efcore
File: src/dotnet-ef/Project.cs (C#)

Code before:

        args.Add("/getProperty:Platform");

        args.Add("/t:ResolvePackageAssets");
        args.Add("/getItem:RuntimeCopyLocalItems");

        args.Add(file);

        var output = new StringBuilder();

        Reporter.WriteVerbose(Resources.RunningCommand("dotnet " + string.Join(" ", args)));

        var exitCode = Exe.Run("dotnet", args, handleOutput: line => output.AppendLine(line));
        if (exitCode != 0)
        {
            if (framework == null && HasMultipleTargetFrameworks(file))
            {
                throw new CommandException(Resources.MultipleTargetFrameworks);
            }

            throw new CommandException(Resources.GetMetadataFailed);
        }

        Reporter.WriteVerbose(output.ToString());

        var metadata = JsonSerializer.Deserialize<ProjectMetadata>(output.ToString())!;

        var runtimeCopyLocalItems = metadata.Items["RuntimeCopyLocalItems"];

        var designAssembly = runtimeCopyLocalItems
            .Select(i => i["FullPath"])
            .FirstOrDefault(i => i.Contains("Microsoft.EntityFrameworkCore.Design", StringComparison.InvariantCulture))
            ?.Replace('\\', Path.DirectorySeparatorChar);
        var properties = metadata.Properties;

        var normalizedOutputPath = properties[nameof(OutputPath)]!.Replace('\\', Path.DirectorySeparatorChar);
        var normalizedProjectDir = properties[nameof(ProjectDir)]!.Replace('\\', Path.DirectorySeparatorChar);
        var normalizedProjectAssetsFile = properties[nameof(ProjectAssetsFile)]?.Replace('\\', Path.DirectorySeparatorChar);
        var outputPath = Path.GetFullPath(Path.Combine(normalizedProjectDir, normalizedOutputPath));
        CopyBuildHost(runtimeCopyLocalItems, outputPath);

        var platformTarget = properties[nameof(PlatformTarget)];
        if (platformTarget.Length == 0)
        {
            platformTarget = properties["Platform"];
        }

        return new Project(file, framework, configuration, runtime)
        {
            AssemblyName = properties[nameof(AssemblyName)],
            DesignAssembly = designAssembly,

Review comment (suggestion):
`output.ToString()` is called multiple times here (once for verbose logging and again for JSON deserialization), which allocates a new string each time. Consider materializing it once into a local variable and reusing it for both logging and `JsonSerializer.Deserialize`.
```suggestion
        var outputString = output.ToString();
        Reporter.WriteVerbose(outputString);

        var metadata = JsonSerializer.Deserialize<ProjectMetadata>(outputString)!;
```

Code after:

        args.Add("/getProperty:Platform");

        args.Add("/t:ResolvePackageAssets");
        args.Add("/getItem:RuntimeCopyLocalItems");

        args.Add(file);

        var output = new StringBuilder();

        Reporter.WriteVerbose(Resources.RunningCommand("dotnet " + string.Join(" ", args)));

        var exitCode = Exe.Run("dotnet", args, handleOutput: line =>
        {
            output.AppendLine(line);
            Reporter.WriteVerbose(line);
        });
        if (exitCode != 0)
        {
            if (framework == null && HasMultipleTargetFrameworks(file))
            {
                throw new CommandException(Resources.MultipleTargetFrameworks);
            }

            throw new CommandException(Resources.GetMetadataFailed);
        }

        var metadata = JsonSerializer.Deserialize<ProjectMetadata>(output.ToString())!;

        var runtimeCopyLocalItems = metadata.Items["RuntimeCopyLocalItems"];

        var designAssembly = runtimeCopyLocalItems
            .Select(i => i["FullPath"])
            .FirstOrDefault(i => i.Contains("Microsoft.EntityFrameworkCore.Design", StringComparison.InvariantCulture))
            ?.Replace('\\', Path.DirectorySeparatorChar);
        var properties = metadata.Properties;

        var normalizedOutputPath = properties[nameof(OutputPath)]!.Replace('\\', Path.DirectorySeparatorChar);
        var normalizedProjectDir = properties[nameof(ProjectDir)]!.Replace('\\', Path.DirectorySeparatorChar);
        var normalizedProjectAssetsFile = properties[nameof(ProjectAssetsFile)]?.Replace('\\', Path.DirectorySeparatorChar);
        var outputPath = Path.GetFullPath(Path.Combine(normalizedProjectDir, normalizedOutputPath));
        CopyBuildHost(runtimeCopyLocalItems, outputPath);

        var platformTarget = properties[nameof(PlatformTarget)];
        if (platformTarget.Length == 0)
        {
            platformTarget = properties["Platform"];
        }

        return new Project(file, framework, configuration, runtime)
        {