C# 可以在本地生成/测试中找到测试中引用的文件,但不使用teamservices

C# 可以在本地生成/测试中找到测试中引用的文件,但不使用teamservices,c#,.net,unit-testing,build,azure-devops,C#,.net,Unit Testing,Build,Azure Devops,我是.net核心构建过程的新手,所以我的问题可能很简单,但到目前为止我还没有弄清楚。因此,任何提示都将不胜感激 我已经按照这个结构创建了一个VisualStudio解决方案 MoCap1(解决方案) -src -C3D(我的主要项目) -project.json(等) -试验 -C3D.试验(相应的试验项目) -project.json(等) -C3DParserTests.cs(包含以下提到的测试的文件) 此结构用于光盘和Visual Studio 2015中的解决方案资源管理器 在C3DP

我是.net核心构建过程的新手,所以我的问题可能很简单,但到目前为止我还没有弄清楚。因此,任何提示都将不胜感激

我已经按照这个结构创建了一个VisualStudio解决方案

MoCap1(解决方案)
-src
-C3D(我的主要项目)
-project.json(等)
-试验
-C3D.试验(相应的试验项目)
-project.json(等)
-C3DParserTests.cs(包含以下提到的测试的文件)

此结构用于光盘和Visual Studio 2015中的解决方案资源管理器

在C3DParserTests.cs中,我定义了以下测试:

        [Fact]
        public void Parse()
        {
            /*
             * positive tests
             */
            C3DParser parser = new C3DParser();
            C3DModel model = parser.Parse(File.ReadAllBytes(@"Data\HDM_bd_01-01_01_120.c3d"));

            Assert.NotNull(model);

            // check header info
            Assert.Equal(2, model.ParameterSectionStart);
        }
如您所见,引用了一个.c3d文件。使用Visual Studio进行测试时,可以找到文件,并且测试成功。使用teamservices和我的构建过程时,我遇到以下错误:

xUnit.net .NET CLI test runner (64-bit .NET Core win81-x64)
  Discovering: C3D.Tests
  Discovered:  C3D.Tests
  Starting:    C3D.Tests
    C3D.Tests.C3DParserTests.Parse [FAIL]
      System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\a\1\s\Data\HDM_bd_01-01_01_120.c3d'.
      Stack Trace:
           at System.IO.Win32FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
           at System.IO.Win32FileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
           at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
           at System.IO.File.InternalReadAllBytes(String path)
           at System.IO.File.ReadAllBytes(String path)
        C:\a\1\s\MoCap1\test\C3D.Tests\C3DParserTests.cs(22,0): at C3D.Tests.C3DParserTests.Parse()
    C3D.Tests.C3DParserTests.ParseNegative [FAIL]
      System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\a\1\s\Data\HDM_bd_01-01_01_120.c3d'.
      Stack Trace:
           at System.IO.Win32FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
           at System.IO.Win32FileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
           at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
           at System.IO.File.InternalReadAllBytes(String path)
           at System.IO.File.ReadAllBytes(String path)
        C:\a\1\s\MoCap1\test\C3D.Tests\C3DParserTests.cs(40,0): at C3D.Tests.C3DParserTests.ParseNegative()
  Finished:    C3D.Tests
=== TEST EXECUTION SUMMARY ===
   C3D.Tests  Total: 4, Errors: 0, Failed: 2, Skipped: 0, Time: 0.349s
SUMMARY: Total: 1 targets, Passed: 0, Failed: 1.
Process completed with exit code 1.
这是有道理的,因为这条路

C:\a\1\s\Data\HDM\u bd\u 01-01\u 01\u 120.c3d

不存在。这是构建步骤的输出,您可以在其中看到正确的路径

Done Building Project "C:\a\1\s\MoCap1\src\C3D\C3D.xproj" (default targets).
The target "_ConvertPdbFiles" listed in a BeforeTargets attribute at "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets (34,37)" does not exist in the project, and will be ignored.
The target "_CollectPdbFiles" listed in an AfterTargets attribute at "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets (34,70)" does not exist in the project, and will be ignored.
The target "_CollectMdbFiles" listed in a BeforeTargets attribute at "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets (41,38)" does not exist in the project, and will be ignored.
The target "_CopyMdbFiles" listed in an AfterTargets attribute at "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets (41,71)" does not exist in the project, and will be ignored.
Project "C:\a\1\s\MoCap1\MoCap1.sln" (1) is building "C:\a\1\s\MoCap1\test\C3D.Tests\C3D.Tests.xproj" (3) on node 1 (default targets).
PrepareForBuild:
  Creating directory ".\bin\".
  Creating directory ".\obj\Release\".
CoreCompile:
  C:\Program Files\dotnet\dotnet.exe build "C:\a\1\s\MoCap1\test\C3D.Tests" --configuration Release --no-dependencies
  Project C3D.Tests (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
  Compiling C3D.Tests for .NETCoreApp,Version=v1.0
  Compilation succeeded.
      0 Warning(s)
      0 Error(s)
  Time elapsed 00:00:01.8894809

Done Building Project "C:\a\1\s\MoCap1\test\C3D.Tests\C3D.Tests.xproj" (default targets).
Done Building Project "C:\a\1\s\MoCap1\MoCap1.sln" (default targets).
Build succeeded.
    0 Warning(s)
    0 Error(s)
Time Elapsed 00:00:43.29
用于测试的dotNet构建步骤产生以下输出:

Starting: Run dotnet
******************************************************************************
dotnet test C:\a\1\s\MoCap1\test\C3D.Tests -xml testresultsC3D.xml
Project C3D (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling C3D for .NETCoreApp,Version=v1.0
Compilation succeeded.
    0 Warning(s)
    0 Error(s)
Time elapsed 00:00:01.8492346
Project C3D.Tests (.NETCoreApp,Version=v1.0) will be compiled because dependencies changed
Compiling C3D.Tests for .NETCoreApp,Version=v1.0
Compilation succeeded.
    0 Warning(s)
    0 Error(s)
Time elapsed 00:00:01.7167452
你能给我一些解决这个问题的建议吗

致以最良好的祝愿


Nils

如何为主项目创建xunittest项目?您可以提供详细的步骤,也可以在OneDrive上共享一个简单的项目。它建造得很好。(相关代码[事实]public void ReadFileTest(){byte[]b=File.ReadAllBytes(@“Data2\tt.txt”);string result=System.Text.Encoding.UTF8.GetString(b);Assert.Equal(“hello”,result);})。构建步骤的细节是什么,如何指定命令行步骤的工作文件夹?为了运行测试,我使用命令行步骤(dotnet测试)。项目的结构是什么?构建是否生成了“HDM_bd_01-01_01_120.c3d”文件?