首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在带有目标框架的.Net核心项目上运行VS测试.Net框架4.7不起作用

在带有目标框架的.Net核心项目上运行VS测试.Net框架4.7不起作用
EN

Stack Overflow用户
提问于 2018-02-19 15:59:15
回答 1查看 952关注 0票数 1

我有一个.Net核心API项目。它必须为.Net框架使用一些第三方库(与net47不兼容),因此我们在.csproj中将TargetFramework属性从"netcoreapp2.0“更改为"net47":

代码语言:javascript
复制
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
    <!-- <TargetFramework>netcoreapp2.0</TargetFramework> -->
    <TargetFramework>net47</TargetFramework>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
代码语言:javascript
复制
Everything is working fine apart from the fact that I'm not able to create test projects on this.

I like to use NUnit.
 I tried to create .net core test project (using both MS Unit Test and XUnit) but them are both unable to run the test.
 "Run test" is simply ignored.  

I created also a .Net Framework test project and in this case I have an error at runtime when the test try to use some classes from the "fake" .Net Core project.  

The error is this:

>  Message: System.BadImageFormatException : Could not load file or assembly 'MyCompany.ProjectA.Api, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
>  

Another developer that use ReSharper can run the test created with .Net Core without any problem.
 It is discovered (using ReSharper) and it can be debugged.

Please do not suggest me to NOT use "net47" in the project file.  It is not an option.  

Additional info.
 The test project is loading the correct packages:

```javascript
代码语言:javascript
复制
same problem (test dot discovered or ignored on "run") adding these:

```javascript
代码语言:javascript
复制
When the test is ignored the error in the console is this:  

```javascript

19/02/2018 16:01:28警告异常System.InvalidOperationException,在System.InvalidOperationException中抛出异常执行测试

19/02/2018 16:01:28由于对象的当前状态,警告操作无效。

19/02/2018 16:01:28在Mono.Cecil.ModuleDefinition.ProcessDebugHeader()警告

在Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader阅读器)

在Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition模块中,ReaderParameters参数)

在Mono.Cecil.ModuleReader.CreateModuleFrom(Image图像上,ReaderParameters参数)

在Mono.Cecil.ModuleDefinition.ReadModule(流,ReaderParameters参数)

在Mono.Cecil.ModuleDefinition.ReadModule(String fileName,ReaderParameters参数)

在NUnit.VisualStudio.TestAdapter.NavigationDataProvider.CacheNewTypes(String assemblyPath,IDictionary`2 `2类型)在C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NavigationDataProvider.cs:line 103中

在NUnit.VisualStudio.TestAdapter.NavigationDataProvider.GetNavigationData(String className,String methodName)在C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NavigationDataProvider.cs:line 48中

在NUnit.VisualStudio.TestAdapter.TestConverter.MakeTestCaseFromXmlNode(XmlNode testNode) ( C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\TestConverter.cs:line 144 )

在NUnit.VisualStudio.TestAdapter.TestConverter.ConvertTestCase(XmlNode testNode)在C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\TestConverter.cs:line 79

在NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunAssembly(String assemblyPath,TestFilter filter)在C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 249中

代码语言:javascript
复制
**[Solution]**
 I've removed the [RID](https://learn.microsoft.com/en-us/dotnet/core/rid-catalog) from the API project and the is found and run.

```javascript

win7 7-x64

代码语言:javascript
复制

我试图将它更改为"win-x86“,或者将测试项目从非选择(=任何CPU)更改为x86或x64。

所有这些都不是一个好的解决办法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-19 16:05:17

我认为你遇到了32位/64位的冲突,你可以看到这样的答案:无法加载文件或程序集.尝试加载格式不正确的程序(System.BadImageFormatException)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48869785

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档