Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Load failure for .NET Core cs projects without Sdk attribute in Project element
ma111
#1 Posted : Wednesday, June 12, 2019 11:54:33 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/12/2019(UTC)
Posts: 2
Location: United States of America

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
NCrunch fails to load C# .NET Core project files that don't have the Sdk attribute in the Project element. However this attribute is not required by MSBuild and there are cases where it should not be present: Microsoft Documentation

This can be reproduced with a test project with the following csproj:

Code:
<Project>
  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
    <PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
  </ItemGroup>

  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>


The following, equivalent csproj results in a successful load

Code:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
    <PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
  </ItemGroup>
</Project>


As does this, simply leaving the Sdk attribute empty:

Code:
<Project Sdk="">
  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
    <PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
  </ItemGroup>

  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>


Below is the full error:

Code:
System.Exception: Unable to find the project declaration in this file.  This does not appear to be a valid MSBuild project file
  at nCrunch.Compiler.BuildXml.AddDefaultBuildTarget(String newTargetName)
  at  .(BuildXml , String )
  at nCrunch.Compiler.LoadTimeQuery..ctor(BuildXml buildXml, IList`1 importExpressions, IPlatformTypeFactory[] platformTypeFactories, IList`1 loadTimeQueryDeclarations)
  at nCrunch.Compiler.ComponentAnalysisContext..ctor(ComponentLoadParameters loadParameters, IBuildableProject buildableProject, DirectoryPath baseIntermediateOutputPath)
  at nCrunch.Compiler.RemoteBuildRunner.AnalyseComponentBuild(ComponentLoadParameters parameters)
  --- End of inner exception stack trace ---
  at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
  at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
  at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  at nCrunch.TaskRunner.Ipc.IpcMessageProcessor.(CallMethodMessage )
  at nCrunch.TaskRunner.Ipc.IpcMessageProcessor.ProcessMessageReturningResult(Byte[] data)
  at nCrunch.TaskRunner.Ipc.RemoteInstance.(Byte[] )
  at nCrunch.TaskRunner.Ipc.RemoteInstance.Invoke(IMessage msg)
  at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
  at nCrunch.Compiler.IRemoteBuildRunner.AnalyseComponentBuild(ComponentLoadParameters parameters)
  at nCrunch.Core.BuildManagement.BuildProcessLauncher..(IRemoteBuildRunner )
  at nCrunch.Core.BuildManagement.BuildProcessLauncher.(Action`1 , FilePath , String , ExternalProcess )
  at nCrunch.Core.BuildManagement.BuildProcessLauncher.(Action`1 , EffectiveProcessorArchitecture , GridClientId , BuildSystemParameters , IList`1 , Nullable`1 , GridAddress )
  at nCrunch.Core.BuildManagement.BuildProcessLauncher.AnalyseComponentBuildInExternalProcess(ComponentLoadParameters parameters, IList`1 customEnvironmentVariables)
  at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.(EffectiveProcessorArchitecture , String )
  at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.CreateComponentFromXml(FilePath projectFilePath, ParsedBuildXml projectXml, FilePath solutionFilePath, String[] additionalFilesToIncludeAtSolutionLevel, Boolean isLoadedFromFile, VisualStudioVersion vsVersion, ComponentUniqueName componentName, TaskSettings componentTaskSettings, Exception parseException, String targetFramework)


Is this known or expected? Is there a way around this other than adding Sdk="" as an attribute to the Project element?

Thanks
Remco
#2 Posted : Friday, June 14, 2019 1:36:04 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,974

Thanks: 929 times
Was thanked: 1256 time(s) in 1169 post(s)
1 user thanked Remco for this useful post.
ma111 on 6/14/2019(UTC)
ma111
#3 Posted : Friday, June 14, 2019 5:22:30 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/12/2019(UTC)
Posts: 2
Location: United States of America

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Confirmed that this resolves the problem. Thanks for the quick turnaround!
1 user thanked ma111 for this useful post.
Remco on 6/14/2019(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.044 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download