admin管理员组

文章数量:1356815

I maintain a legacy application recently upgraded to .NET Framework 4.8, with 3 MSTest classes in it. From within VS 2022 I can build and test the application fine. I've got a GitHub Action, which runs in a self-hosted runner on one of our servers. It gives me several errors all of this sort:

D:\actions-runner_work\Legacy_App\Legacy_App\PJATools.Tests\TestBirthday.cs(57,10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?) [D:\actions-runner_work\Legacy_App\Legacy_App\PJATools.Tests\PJATools.Tests.csproj]

I've searched for that error and found several places that discuss it, but all saying that an assembly is not referenced. In this case that is not true. The 3 MSTest classes all reference Microsoft.VisualStudio.TestTools.UnitTesting and all the test methods have the TestCategory (TestMethodAttribute) defined and are recongized in VS 2022. Here's the beginning of one of the methods:

[TestMethod]
[TestCategory("Test PJA.Birthday")]
public void TestDateOfBirth()
{

So, why am I getting this error in the self-hosted runner of the GitHub Action, but don't when I test it in VS 2022?

Addendum

Here's the code snippet that's failing in my YAML file:

- name: Setup MSBuild.exe
  uses: microsoft/[email protected]

- name: Build solution
  run: msbuild $env:Solution_Name /p:Configuration=Release

本文标签: cWhy doesn39t MSBuild recognize TestCategoryStack Overflow