Build/Test Issues

Unable to make NCrunch build anything with optimized code and without debugging symbols

Started by Magnus Lidbom on 1,629 views

I have tried everything I can think of and have been banging my head against the wall for hours with this problem now.
I'm to the point of having this csproj file and still NCrunch builds it with full debug info and optimizations disabled:

.csproj

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

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <IsPackable>false</IsPackable>

    <Optimize>true</Optimize>
    <DebugType>none</DebugType>
    <DebugSymbols>false</DebugSymbols>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <Optimize>true</Optimize>
    <DebugType>none</DebugType>
    <DebugSymbols>false</DebugSymbols>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DebugType>none</DebugType>
    <DebugSymbols>false</DebugSymbols>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="nunit" Version="3.12.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
  </ItemGroup>

</Project>



Of course I have disabled "Instrument Output Assembly"

When I browse to the "workspace used for selected test" there is a pdb there staring me in the face. And when I open the dll in dotPeek this stares me in the face:


[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]


Please help. I really need this to work since I'm currently doing low level optimizations.
Hi, thanks for posting.

When building the project, NCrunch always sets Optimize=false and DebugType=full (or DebugType=portable) to force the build system to compile the assembly in debug mode. This is done because many of the downstream features (i.e. code coverage, instrumentation, etc) rely on having debug information in order to work. It was introduced because we had many first time users experiencing problems with getting the product to work on incorrectly configured projects.

It's possible to override this behaviour using the 'Custom Build Properties' setting. Set Optimize=true and DebugType=portable in this setting and you'll get the result you're after, though you'll need to put things back again later if you want your NCrunch code coverage to work.

Post a reply

Log in to reply.