我正在学习C#,因此如果不能很精确地描述错误,我深表歉意。
我正在学习Pluralsight课程,在单元测试部分,我意识到单元测试不在我的项目中运行。
它会引发以下错误:
[19/11/2018 22:13:26 Error] Failed to launch testhost with error: System.AggregateException: One or more errors occurred. ---> Microsoft.Build.Exceptions.InvalidProjectFileException: The project file could not be loaded. Could not find file 'C:\Users\Daniele\source\repos\DateTime\UnitTestProject1\bin\x86\Debug\UnitTestProject1.build.appxrecipe'. C:\Users\Daniele\source\repos\DateTime\UnitTestProject1\bin\x86\Debug\UnitTestProject1.build.appxrecipe ---> System.IO.FileNotFoundException: Could not find file 'C:\Users\Daniele\source\repos\DateTime\UnitTestProject1\bin\x86\Debug\UnitTestProject1.build.appxrecipe'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Microsoft.Build.Internal.XmlReaderExtension..ctor(String file)
at Microsoft.Build.Construction.ProjectRootElement.LoadDocument(String fullPath, Boolean preserveFormatting)
--- End of inner exception stack trace ---
at Microsoft.Build.Shared.ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(Boolean condition, String errorSubCategoryResourceName, BuildEventFileInfo projectFile, Exception innerException, String resourceName, Object[] args)
at Microsoft.Build.Construction.ProjectRootElement.LoadDocument(String fullPath, Boolean preserveFormatting)
at Microsoft.Build.Construction.ProjectRootElement..ctor(String path, ProjectRootElementCache projectRootElementCache, Boolean preserveFormatting)
at Microsoft.Build.Construction.ProjectRootElement.CreateProjectFromPath(String projectFile, ProjectRootElementCache projectRootElementCache, Boolean preserveFormatting)
at Microsoft.Build.Construction.ProjectRootElement.<>c.<OpenProjectOrSolution>b__201_0(String path, ProjectRootElementCache cache)
at Microsoft.Build.Evaluation.ProjectRootElementCache.Get(String projectFile, OpenProjectRootElement openProjectRootElement, Boolean isExplicitlyLoaded, Nullable`1 preserveFormatting)
at Microsoft.Build.Construction.ProjectRootElement.OpenProjectOrSolution(String fullPath, IDictionary`2 globalProperties, String toolsVersion, ProjectRootElementCache projectRootElementCache, Boolean isExplicitlyLoaded)
at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion)
at Microsoft.VisualStudio.UwpTestHostRuntimeProvider.RecipeFile.get_Project()
at Microsoft.VisualStudio.UwpTestHostRuntimeProvider.RecipeFile.get_Architecture()
at Microsoft.VisualStudio.UwpTestHostRuntimeProvider.Deployer.Microsoft.VisualStudio.UwpTestHostRuntimeProvider.IDeployer.get_DeploymentArchitecture()
at Microsoft.VisualStudio.UwpTestHostRuntimeProvider.UwpTestHostManager.<LaunchHostAsync>d__35.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.UwpTestHostRuntimeProvider.UwpTestHostManager.<Microsoft-VisualStudio-TestPlatform-ObjectModel-Host-ITestRuntimeProvider-LaunchTestHostAsync>d__30.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources)
---> (Inner Exception #0) Microsoft.Build.Exceptions.InvalidProjectFileException: The project file could not be loaded. Could not find file 'C:\Users\Daniele\source\repos\DateTime\UnitTestProject1\bin\x86\Debug\UnitTestProject1.build.appxrecipe'. C:\Users\Daniele\source\repos\DateTime\UnitTestProject1\bin\x86\Debug\UnitTestProject1.build.appxrecipe ---> System.IO.FileNotFoundException: Could not find file 'C:\Users\Daniele\source\repos\DateTime\UnitTestProject1\bin\x86\Debug\UnitTestProject1.build.appxrecipe'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Microsoft.Build.Internal.XmlReaderExtension..ctor(String file)
at Microsoft.Build.Construction.ProjectRootElement.LoadDocument(String fullPath, Boolean preserveFormatting)
--- End of inner exception stack trace ---
at Microsoft.Build.Shared.ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(Boolean condition, String errorSubCategoryResourceName, BuildEventFileInfo projectFile, Exception innerException, String resourceName, Object[] args)
at Microsoft.Build.Construction.ProjectRootElement.LoadDocument(String fullPath, Boolean preserveFormatting)
at Microsoft.Build.Construction.ProjectRootElement..ctor(String path, ProjectRootElementCache projectRootElementCache, Boolean preserveFormatting)
at Microsoft.Build.Construction.ProjectRootElement.CreateProjectFromPath(String projectFile, ProjectRootElementCache projectRootElementCache, Boolean preserveFormatting)
at Microsoft.Build.Construction.ProjectRootElement.<>c.<OpenProjectOrSolution>b__201_0(String path, ProjectRootElementCache cache)
at Microsoft.Build.Evaluation.ProjectRootElementCache.Get(String projectFile, OpenProjectRootElement openProjectRootElement, Boolean isExplicitlyLoaded, Nullable`1 preserveFormatting)
at Microsoft.Build.Construction.ProjectRootElement.OpenProjectOrSolution(String fullPath, IDictionary`2 globalProperties, String toolsVersion, ProjectRootElementCache projectRootElementCache, Boolean isExplicitlyLoaded)
at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion)
at Microsoft.VisualStudio.UwpTestHostRuntimeProvider.RecipeFile.get_Project()
at Microsoft.VisualStudio.UwpTestHostRuntimeProvider.RecipeFile.get_Architecture()
at Microsoft.VisualStudio.UwpTestHostRuntimeProvider.Deployer.Microsoft.VisualStudio.UwpTestHostRuntimeProvider.IDeployer.get_DeploymentArchitecture()
at Microsoft.VisualStudio.UwpTestHostRuntimeProvider.UwpTestHostManager.<LaunchHostAsync>d__35.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.UwpTestHostRuntimeProvider.UwpTestHostManager.<Microsoft-VisualStudio-TestPlatform-ObjectModel-Host-ITestRuntimeProvider-LaunchTestHostAsync>d__30.MoveNext()<---
[19/11/2018 22:13:26 Informational] ========== Run test finished: 0 run (0:00:00.0535907) ==========
和其他解决方案:
首先禁用VPN(我没有),然后在提升的PowerShell提示符下运行“set-mppreference -EnableNetworkProtection 0”
,然后重新启动VS。
这种方法最终都无法奏效,我无法运行任何测试。
答案 0 :(得分:1)
问题是appxrecipe不在单元测试项目的bin文件夹中。
您可以通过为单元测试项目创建一个应用程序包来创建appxrecipe文件。要创建应用程序包,请右键单击您的单元测试项目>“商店”>“创建应用程序包”。
完成后,appxrecipe文件应位于项目的bin文件夹中,Visual Studio应该能够运行单元测试。