Build/Test Issues

ncrunch cant build Xamarin.Forms 3.0

Started by danius on 8,496 views

After adding XF3 to .net standard 2 project, ncrunch is failing to build.
Building through Visual studio or running msbuild in command prompt is fine.
Downgrading to Xamarin.Forms 2.5 hides this error, but complains about xamarin targets not matching.


VS version 15.7
nCrunch 3.15.0.6

Error below. (Same for all XAML files).


obj\Debug\netstandard2.0\App.xaml (0, 0): Could not load file or assembly 'System.Security.Cryptography.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.


Could you point me in the right direction please. It's confusing because VS can build and run apps.
And NCrunch worked before last VS update.
Help appreciated.

Thanks,
Daniel

Edited

Hi Daniel,

Thanks for sharing this problem.

Unfortunately, Xamarin in all its forms is not officially supported by NCrunch. Xamarin uses a different build system to other .NET-based projects and no investment has been made to handle its edge cases or keep it updated with changes in the ecosystem. If this project worked for you in older versions of Xamarin, it was coincidental and there is a high chance of downstream problems appearing.

It may be possible to work around these problems through configuration by setting NCrunch in compatibility mode as this will bring NCrunch's build system more in alignment with a standard VS-based build.

If you want to see support extended for this platform you are most welcome to vote for it as a future feature for the product.
Thanks for coming back. I will play with settings and I appreciate that Xamarin is not covered by NCrunch, but this project is actually .net Standard 2.0 that's using Xamarin.Forms nuget package.
It was compiling and running tests against. So I think it's just something in the latest VS build

I will keep digging.

Daniel
Sorry Daniel - I misunderstood in thinking this was actually a Xamarin project.

I do definitely recommend trying the compatibility mode to see if that resolves the problem. It's likely that there is a XAML build step that is malfunctioning because of NCrunch's workspacing. If you can find the reference to this build step in your project you may be able to selectively disable it for NCrunch as it likely isn't required for your automated tests to run.

Sometimes things can go wrong with your project.assets.json file when juggling Nuget references and this can cause resolution issues. Clearing out your obj/bin directories with VS closed can often solve these problems.
Downgrading nugets solved it for me, I will have to come back to this later. Build process and all the .targets logic still escapes my small brain.

Same problem for me. I tried to clean solution + removing bin/obj/packages, still not working. Even compatibility mode does not solve the problem, unfortunately.

Edited

I've taken a deeper look at this problem and confirmed that it is a compatibility issue between NCrunch and the Xamarin toolset.

Although this is a netstandard project, adding the reference to Xamarin.Forms includes a range of Xamarin build targets including additional compilers and complex steps. So it's probably safe to say that when you do this, you're actually making a Xamarin project.

In my testing, the problem originated from the XamlCTask. It seems to be possible to selectively disable this for NCrunch builds by applying the _XamlCAlreadyExecuted property to the project, as such:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
	<_XamlCAlreadyExecuted Condition="'$(NCrunch)' == '1'">true</_XamlCAlreadyExecuted>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="3.0.0.482510" />
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Update="Page1.xaml">
      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
    </EmbeddedResource>
  </ItemGroup>

</Project>


Note that this will completely disable the Xamarin compile step when building the projects under NCrunch. Any code depending on the embedded resources produced by this step will likely fail. It may be enough to get your unit tests to function.

Unfortunately this is as far as I can go with providing support in this area. We have performed no development or testing with NCrunch on the Xamarin platform, so we cannot warrant that it will work and cannot invest time in investigating issues on an unsupported platform. If you'd like to see proper support added for Xamarin in future, you are most welcome to vote for it on uservoice.

Edited

Many thanks, Remco, you solved my issues.
We encountered same issue - and was not fixable with _XamlCAlreadyExecuted cause Xamarin project has removed that from their code ;-(

We have edited as a workaround Xamarin.forms.targets and added there the condition Condition="'$(NCrunch)' == '1'" to the <Target Name="XamlC" ... line.
Works for the moment but is far from practicable.

I added a feature request to support Xamarin in visual studio 2017 - vote

Hello everyone,

Is it possible for NCrunch to update to 4.0.3 versions of dlls or ensure that the references it needs don't have to be present in the project being built? I've tried all of the compatibility options and neither help.

Edited

This post has been deleted.
I confirm that NCrunch is compatible with Xamarin.Forms 3.1.0!

All you need to do is add the following line to your csproj:

<DesignTimeBuild Condition="'$(NCrunch)' == '1'">true</DesignTimeBuild>


Example:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <PropertyGroup>
    <DebugType>pdbonly</DebugType>
    <DesignTimeBuild Condition="'$(NCrunch)' == '1'">true</DesignTimeBuild>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="3.1.0.637273" />
    <PackageReference Include="Xamarin.Forms.Maps" version="3.1.0.637273" />
  </ItemGroup>
</Project>

Edited

Post a reply

Log in to reply.