Closed BrunoGuardia closed 1 year ago
Until .Net 6.x, we were able to run
dotnet test App.sln -p Property=Value
and the property was adequately passed down to MSBuild, interpreted by project files and the like.
On upgrading to .Net 7.x, we found the property was no longer passed down. However, we have a workaround
dotnet test -p Property=Value App.sln
Fail - runs only one test dotnet test TestProject1.csproj -p:CIBuild=Integration
dotnet test TestProject1.csproj -p:CIBuild=Integration
Correct - runs only one test dotnet test -p:CIBuild=Unit TestProject1.csproj
dotnet test -p:CIBuild=Unit TestProject1.csproj
Correct - runs the two tests dotnet test -p:CIBuild=Integration TestProject1.csproj
dotnet test -p:CIBuild=Integration TestProject1.csproj
TestProject1.csproj
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net7.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <IsPackable>false</IsPackable> <ApplicationManifest>app.manifest</ApplicationManifest> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" /> <PackageReference Include="MSTest.TestAdapter" Version="2.2.10" /> <PackageReference Include="MSTest.TestFramework" Version="2.2.10" /> <PackageReference Include="coverlet.collector" Version="3.1.2" /> </ItemGroup> </Project>
Directory.Build.props
<Project> <PropertyGroup> <LangVersion>11.0</LangVersion> <TargetFramework>net7.0</TargetFramework> <RunSettingsFilePath>$(MSBuildThisFileDirectory)Unit.runsettings</RunSettingsFilePath> <RunSettingsFilePath Condition="$(CIBuild) != ''">$(MSBuildThisFileDirectory)$(CIBuild).runsettings</RunSettingsFilePath> </PropertyGroup> </Project>
Unit.runsettings
<RunSettings> <RunConfiguration> <TestCaseFilter>TestCategory=Unit</TestCaseFilter> </RunConfiguration> </RunSettings>
Integration.runsettings
<RunSettings> <RunConfiguration> <TestCaseFilter>TestCategory=Unit|TestCategory=Integration</TestCaseFilter> </RunConfiguration> </RunSettings>
UnitTest1.cs
namespace TestProject1 { [TestClass] public class UnitTest1 { [TestMethod, TestCategory("Unit")] public void TestMethod1() { } [TestMethod, TestCategory("Integration")] public void TestMethod2() { } } }
No exceptions
dotnet --info
` .NET SDK: Version: 7.0.100 Commit: e12b7af219
Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.100\
Host: Version: 7.0.0 Architecture: x64 Commit: d099f075e4
.NET SDKs installed: 3.1.425 [C:\Program Files\dotnet\sdk] 6.0.202 [C:\Program Files\dotnet\sdk] 6.0.306 [C:\Program Files\dotnet\sdk] 7.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables: Not set
global.json file: Not found
Learn more: https://aka.ms/dotnet/info
Download .NET: https://aka.ms/dotnet/download `
Passing properties seem to have worked since earlier versions, but it is not well documented.
Hi @BrunoGuardia - This is a duplicate of https://github.com/microsoft/vstest/issues/4014. We've merged a fix already and the fix will be available in 7.0.101 early/mid next month.
Describe the bug
Until .Net 6.x, we were able to run
dotnet test App.sln -p Property=Value
and the property was adequately passed down to MSBuild, interpreted by project files and the like.
On upgrading to .Net 7.x, we found the property was no longer passed down. However, we have a workaround
dotnet test -p Property=Value App.sln
To Reproduce
Fail - runs only one test
dotnet test TestProject1.csproj -p:CIBuild=Integration
Correct - runs only one test
dotnet test -p:CIBuild=Unit TestProject1.csproj
Correct - runs the two tests
dotnet test -p:CIBuild=Integration TestProject1.csproj
TestProject1.csproj
Directory.Build.props
Unit.runsettings
Integration.runsettings
UnitTest1.cs
Exceptions (if any)
No exceptions
Further technical details
dotnet --info
` .NET SDK: Version: 7.0.100 Commit: e12b7af219
Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.100\
Host: Version: 7.0.0 Architecture: x64 Commit: d099f075e4
.NET SDKs installed: 3.1.425 [C:\Program Files\dotnet\sdk] 6.0.202 [C:\Program Files\dotnet\sdk] 6.0.306 [C:\Program Files\dotnet\sdk] 7.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables: Not set
global.json file: Not found
Learn more: https://aka.ms/dotnet/info
Download .NET: https://aka.ms/dotnet/download `
Related
Passing properties seem to have worked since earlier versions, but it is not well documented.
23198