Skip to content

Microsoft.Testing.Extensions.TrxReport should allow customizing trx file name via dedicated MSBuild property #6648

Description

Summary

The only way to currently customize the .trx filename when using MTP with the Microsoft.Testing.Extensions.TrxReport extension is by using the much more general purpose TestingPlatformCommandLineArguments MSBuild property.

I believe forcing the use of this single property makes for a more convoluted configuration experience and creates maintenance/flexibility issues for consumers.

A dedicated, more specific property should be provided that only concerns itself with the format of the trx file and nothing else.

Background and Motivation

We integrated .trx-based test reports in our GitHub workflows this week and it was a pain to get things to how we wanted. The current defaults for the file name are, in my opinion, awful, so we wanted to change them to something that would be more readable to the outside.

We used the dorny/test-reporter GitHub action to parse the .trx files from each of our projects and generate the test report. The tool relies on the filename to produce the various sections in its report (which by itself makes sense).

We made it work by configuring the TestingPlatformCommandLineArguments property like this:

<TestingPlatformCommandLineArguments>--report-trx --report-trx-filename $(MSBuildProjectName).trx</TestingPlatformCommandLineArguments>

Which worked, but with some caveats.

The main issue is that this basically forces us to now always output a trx report, even when we don't want to. Because the way these properties work (as cmdline arguments) it is not possible to only specify --report-trx-filename, otherwise dotnet test will crash with an error saying that --report-trx-filename must be used in conjunction with --report-trx.

From a CLI tool's perspective, this is very reasonable, but because the CLI argument list is the only way to customize those values, it now becomes impossible to just change the format of the trx filenames without having to introduce the extra parameters and without forcing the entire command to always run.

Rather, what we really wanted, was to be able to customize just the format of the filename without touching anything else, and we wanted it to apply only when actually requesting a trx report, which we were trying to setup only in our GitHub workflows, not locally.

Yes, it is possible to add a MSBuild Condition to that property with something like:

<TestingPlatformCommandLineArguments Condition="'$(GITHUB_ACTIONS)' == 'true'">--report-trx --report-trx-filename $(MSBuildProjectName).trx</TestingPlatformCommandLineArguments>

But at the end of the day, we decided against that as it was a bit too obscure. We opted for the less-than-ideal approach of "always generate the trx whenever running dotnet test" even though our need was only to do it on server builds.

The fact that it is all cmdline-based also prevents us from attempting something like this, which would be a much cleaner way of handling this (pseudo-code):

<TestingPlatformCommandLineArguments Condition="'$(cmdline_args).Include('--report-trx')">--report-trx-filename $(MSBuildProjectName).trx</TestingPlatformCommandLineArguments>

Because msbuild does not have access to the passed-in cmdline arguments to dotnet test.

We think this would be significantly simpler if there was a dedicated MSBuild property that only concerned itself with the default format of the trx filenames, so that we could set only that, like:

<TrxFileNameFormat>$(MSBuildProjectName)</TrxFileNameFormat>

And then, whenever --report-trx was used, it would just honor this value automatically, so we could be more explicit on the build server using:

dotnet test -- --report-trx

And avoid the unnecessary process from just happening locally for everyone.

Proposed Feature

I propose that a dedicated MSBuild property be created to customize just the format of the filename for .trx files created by Microsoft.Testing.Extensions.TrxReport.

Suggested property name: TrxFileNameFormat

The commandline value, if specified, would still have precedence over this variable, since it is the more direct/explicit setting.

Alternative Designs

I don't see any other approaches that would be as clean as a dedicated MSBuild property for this. This approach allows using the full breadth of options that MSBuild provides including project-specific properties (such as the one we used, $(MSBuildProjectName)) to customize the format in a generic fashion especially in conjunction with a localized Directory.Build.props file.

Such customization is not possible directly at the commandline when we are running dotnet test because that is usually fired in a much broader context (we are calling it with no solution/project arguments so it grabs the default master solution of the entire repo).

At the same time, the existing TestingPlatformCommandLineArguments also doesn't allow us to cleanly override individual aspects of the generation such as the trx filename without forcing us into a whole other set of decisions.

I think this is preferred to other options such as the one described here:

Although I could see both working in conjunction as well as they feel like independent enhancements.

Activity

  1. Youssef1313 commented on Oct 1, 2025

    @Youssef1313
    Member

    I don't think it's a good idea to attempt to let the platform read MSBuild properties at runtime.

    The only viable way I can think of to do this is by using RuntimeHostConfigurationOption.

    TestingPlatformCommandLineArguments is kinda different. It's not read by MTP at runtime at all. It's simply a way to adjust how the exe is run in the first place, so the exe starts right away with the expected command-line arguments, and then MTP just reads those arguments.

    Currently, TestingPlatformCommandLineArguments is the recommended way if you want to adjust TRX name.

  2. added
    state/needs-approval
    area/mtp
    area/trx
    and removed
    needs/triage
    on Oct 1, 2025
  3. julealgon commented on Oct 2, 2025

    @julealgon
    Author

    Youssef Fahmy (@Youssef1313) if msbuild properties is not feasible directly, there must be some other way of handling this. What about propagating environment variables to the MTP executable and customize these values through that?

  4. julealgon commented on Nov 24, 2025

    @julealgon
    Author

    Currently, TestingPlatformCommandLineArguments is the recommended way if you want to adjust TRX name.

    Youssef Fahmy (@Youssef1313) what if I need to run my tests using dotnet test --test-modules?

    I just realized that using that approach, none of the values declared in TestingPlatformCommandLineArguments are honored at all, and we are back to square one: we need to run multiple test dll's, but we can't customize each output trx file based on the executing project, since the CLI has no context of that.

    Now we are kinda stuck with the terrible default names of trx files 😞

    My assumption is that something like this:

    Would resolve my problem.

  5. Evangelink commented on May 16, 2026

    @Evangelink
    Member

    Juliano Leal Goncalves (@julealgon) I don't know if you are still using MTP. If you do, we just implemented the template (not yet shipped), I'd like to get your view on what would be missing for you.

  6. julealgon commented on May 18, 2026

    @julealgon
    Author

    We absolutely are still using MTP and this is still very relevant Amaury Levé (@Evangelink). Where can I find more info/docs on the proposed implementation?

  7. Evangelink commented on Aug 31, 2026

    @Evangelink
    Member

    Juliano Leal Goncalves (@julealgon) Sorry for the very late reply... I completely missed your message.

    The filename-template support I mentioned has now shipped in Microsoft.Testing.Platform 2.3.0. Instead of introducing a dedicated MSBuild property, we added runtime placeholders to report filenames. This also works when using dotnet test --test-modules, where per-project MSBuild properties are not available because MTP is executing already-built test modules.

    For example:

    dotnet test --test-modules <pattern> -- --report-trx --report-trx-filename "{asm}.trx"

    {asm} is replaced with each test module's assembly name. Other placeholders include {tfm}, {arch}, {pname}, {pid}, and {time}. The full documentation is here: https://learn.microsoft.com/dotnet/core/testing/microsoft-testing-platform-test-reports#report-file-names

    I'd really appreciate your feedback on this approach. Does it cover your original scenario? If you still need a dedicated MSBuild property, could you share the specific scenario or values that the template placeholders do not cover? That will help us design the right solution rather than adding a property that only addresses part of the need.

  8. added
    needs/author-feedback
    and removed
    state/needs-approval
    on Aug 31, 2026
  9. julealgon commented on Aug 31, 2026

    @julealgon
    Author

    evangelik it covers some of our use cases, but is not ideal.

    The fact that it is done through CLI arguments forces us to replicate those same arguments on every single one of our repositories.

    We already have our own custom MSBuild SDK for test projects where we standardize all aspects of test projects across the whole company, such as common MSBuild properties, assertion library, test framework, mocking library, etc. If these settings were exposed as MSBuild properties, we would be able to standardize them as well without having to manually update dozens of GitHub actions workflows across the organization.

    Also note that I'm aware there is a MSBuild property to override the commandline arguments for the dotnet test call, but that does not work well for setting defaults as it always propagates the extra command, which is really not what we want at all.

    Lastly, that solution doesn't cover other aspects which we also override today, such as --coverage-output and --coverage-output-format values.

    Basically, as it is, we currently cannot migrate to this approach without loss of capability on our side. I guess we could instead more our standardization into a custom shared GitHub composite action where we wrap dotnet test but that feels significantly more convoluted, and would still require us to update every single workflow in the company to use the new composite action.

    I would still strongly recommend reconsidering here and exposing some of these defaults as MSBuild properties.

    You can keep the CLI templating thing but it would be built on top of the MSBuild properties. They are mostly independent mechanisms.

  10. added
    needs/attention
    and removed
    needs/author-feedback
    on Aug 31, 2026
  11. Evangelink commented on Aug 31, 2026

    @Evangelink
    Member

    Juliano Leal Goncalves (@julealgon) Thanks, I think I understand the distinction now: you want to centralize defaults without those defaults enabling the corresponding feature.

    Would entries in testconfig.json solve this for your custom SDK? We are considering a generic mechanism that any extension could use, rather than adding an MSBuild property for every option. For example:

    {
      "commandLineOptionDefaults": {
        "report-trx-filename": "{asm}.trx",
        "coverage-output": "{asm}.coverage",
        "coverage-output-format": "cobertura"
      }
    }

    The keys would match CLI option names without --. These values would be passive defaults: they would not enable --report-trx or --coverage, and an explicit CLI value would take precedence. Because the configuration travels with the built test module, this should also work with dotnet test --test-modules.

    If a JSON file cannot be supplied centrally by your SDK, we could also consider an MSBuild item that projects these entries into the module configuration, along these lines:

    <ItemGroup>
      <TestingPlatformOptionDefault Include="report-trx-filename" Value="{asm}.trx" />
    </ItemGroup>

    Would the testconfig.json approach cover your centralization scenario, or is an MSBuild-facing entry point necessary for how your SDK is distributed?

  12. julealgon commented on Aug 31, 2026

    @julealgon
    Author

    evangelik

    you want to centralize defaults without those defaults enabling the corresponding feature.

    Exactly.

    Would entries in testconfig.json solve this for your custom SDK?

    Using testconfig.json would also work for us. We actually already provide one as part of our custom SDK as well, so this would be a matter of adding the extra properties there.

    No concerns from my end if the team prefers this approach over MSBuild properties.

  13. Evangelink commented on Sep 1, 2026

    @Evangelink
    Member

    Juliano Leal Goncalves (@julealgon) it will be available in 2.4 releasing by EOW.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/mtparea/trx

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions