question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DeploymentDirectory is 'Out' folder using .NET Framework, but build folder using .NET 6

See original GitHub issue

Description

When running a unit test with MSTest under .NET Framework, the TestContext.DeploymentDirectory path is the ‘Out’ folder inside the test run directory, e.g:

C:\Repositories\MySolution\TestResults\Deploy_User yyyy-MM-dd HH_mm_ss\Out

When running the same test under .NET 6, the TestContext.DeploymentDirectory path is the build directory, e.g:

C:\Repositories\MySolution\MyUnitTestProject\bin\Debug\net6.0

I’ve looked around but this change in behavior between Framework & Core doesn’t seem to be documented anywhere. In fact, the documentation for the DeploymentDirectory property says it’s “typically a subdirectory of TestRunDirectory” - which isn’t the case under .NET 6.

I’ve looked at existing issues; #653 seems similar at first but I think that’s actually related to DeploymentItem rather than DeploymentDirectory despite the title - whereas the issue I’m describing is present whether or not DeploymentItem is used.

Is this a bug or intended behavior?

The reason I’m asking is that I have existing tests which are dependent on this directory being isolated for each run.

Steps to reproduce

Create a new unit test project in .NET 6. Add the following unit test and run it.

[TestMethod]
public void TestDeploymentDirectory()
{
    Assert.IsTrue(TestContext.DeploymentDirectory.StartsWith(TestContext.TestRunDirectory));
}

Expected behavior

The test passes, since the DeploymentDirectory is inside the TestRunDirectory. This is the current behavior if you change the target framework to net480.

Actual behavior

The test fails.

Environment

Windows 10, Visual Studio 2022 v17.1.1 MSTest.TestAdapter v2.2.7 MSTest.TestFramework v2.2.7 Microsoft.NET.Test.Sdk 16.11.0 coverlet.collector 3.1.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:5
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
persncommented, Oct 14, 2022

Is this a bug or intended behavior?

Does anyone know this? It seems like it should be a simple question to answer.

1reaction
craigbrowncommented, Nov 28, 2022

@Evangelink awesome, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

MSTest v2 : Deployment directory set to bin directory
I'm using MSTest v2 with .net6 (vs2022) and i'm running into a problem concerning the deployment of my test files. For a bit...
Read more >
Change the build output directory - Visual Studio (Windows)
Type in the path to generate output to (absolute or relative to the root project directory), or choose Browse to browse to that...
Read more >
ASP.NET Core directory structure
The publish directory contains the app's deployable assets produced by the dotnet publish command. The directory contains:.
Read more >
Building ClickOnce Applications from the Command Line
In this article. Use MSBuild to reproduce .NET Framework ClickOnce application deployments; Create and build a basic ClickOnce application with ...
Read more >
dotnet publish command - .NET CLI
dotnet publish compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found