8

I have .net core test project. When I build it in visual studio or use the TestManager it build without a problem. But when I execute the following command on the package manager console I get an error:

dotnet test C:\projects\moneyfox\Src\MoneyFox.DataAccess.Tests\MoneyFox.DataAccess.Tests.csproj

error:

error MSB4019: The imported project "C:\Program Files\dotnet\sdk\1.0.3\Microsoft\Portable\v5.0\Microsoft.Portable.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk

I checked the path, and there it really doesn't exist. But I'm kinda puzzled what to do with that, since it works when I build it over visual studio. Any suggestions?

NPadrutt
  • 3,619
  • 5
  • 24
  • 60
  • I'm having the same issue. Were you able to figure out the solution? – Babak Naffas May 23 '17 at 05:50
  • Unfortunately not really. I solved it with a solution specific for AppVeyor. – NPadrutt May 23 '17 at 05:55
  • I just used - - no-build. The app is buulded before with VS. So I do not have to build it again here. This worked for me in this context, but it's not really a fix. Let me know if you find out more! – NPadrutt May 23 '17 at 05:58

4 Answers4

3

My solution to this was to convert the project to an Sdk-type csproj.

Check out this answer for tips on how to accomplish this.

In addition to this, I had issues with the analysers so I turned them off via the following csproj properties:

<Project>
  <PropertyGroup>
    <RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
    <RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
    <RunAnalyzers>false</RunAnalyzers>
  </PropertyGroup>
</Project>
Daniel
  • 8,655
  • 5
  • 60
  • 87
1

My test project which was targeted at .Net 6 was referencing a different project that referenced .Net Framework 4.7.2. Once I removed that reference, the error was resolved

Agreene
  • 508
  • 7
  • 16
0

I was able to hack my way around the issue by observing how Visual Studio 2017 was building the project (increase the build verbosity). I'm still uncertain what the actual cause of the issue is and will report the issue to the Xamarin team.

Step 1 - Manually reference the same targets file as Visual Studio

In my.csproj file, I had the following import statement

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />

which I changed to

<Import Project="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Portable\v5.0\Microsoft.Portable.CSharp.targets" />

to match the .targets file that Visual Studio imports.

Once I made this change, my build errors increase because now I was missing references to the standard namespaces (System, System.Net, etc) which Visual Studio magically references on our behalf. I also couldn't add the references to the assemblies via Visual Studio as it complained about duplicate references. So back to the text editor. I manually a=added the following references until my build errors went were resolved.

Step 2 - Manually reference the System* DLLs you need.

<Reference Include="System">
  <HintPath>..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\mscorlib.dll</HintPath>
</Reference>
<Reference Include="System">
  <HintPath>..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.dll</HintPath>
</Reference>    
<Reference Include="System.Linq">
  <HintPath>..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\system.Linq.dll</HintPath>
</Reference>    
<Reference Include="System.Net">
  <HintPath>..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Net.dll</HintPath>
</Reference>        
<Reference Include="System.Net.Http">
  <HintPath>..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Net.Http.dll</HintPath>
</Reference>
Babak Naffas
  • 12,395
  • 3
  • 34
  • 49
0

Visual Studio for Mac VS for Mac supports both dotnet msbuild and MSBuild on Mono. But the .NET SDK version is downgraded when MSBuild on Mono is used, and this can result in the NETSDK1045 error.

Open the Solution Properties window (ctrl-click the solution in the Solution window and select Properties), select Build - General, and uncheck Build with MSBuild on Mono. This Build with MSBuild on Mono option will be checked if there are any classic projects in the solution, and this can cause problems since Mono does not support the later .NET SDKs.

For more information about which Visual Studio for Mac 2022 versions support which .NET versions, see Supported versions of .NET.

Like Below Image Build with MSBuild on Mono

Gladis Wilson
  • 8,400
  • 1
  • 12
  • 12