question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<Import> is emitted after <Choose>

See original GitHub issue

Description

Current versions of Paket emit the <Choose> and <Import Project=...> tags in the incorrect order. It should first emit the <Import> tag, but it first emits the <Choose> tag. This results in problems when using the Roslyn compiler, because the following packages require the proper order of these tags:

  • Microsoft.Net.Compilers
  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Repro steps

  1. Add the Microsoft.Net.Compilers and Microsoft.CodeDom.Providers.DotNetCompilerPlatform to the project.
  2. Run paket update.
  3. Recompile the project.

This will show the following error:

C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.CSharp.Core.targets(76,11): error MSB4064: The "ChecksumAlgorithm" parameter is not supported by the "Csc" task. Verify the parameter exists on the task, and it is a settable public instance property.
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.CSharp.Core.targets(67,5): error MSB4063: The "Csc" task could not be initialized with its input parameters. 

To fix this problem, the .csproj file has to be changed manually. This is the file that is generated by Paket:

  <Choose>
    <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3')">
      <PropertyGroup>
        <__paket__Microsoft_Net_Compilers_props>Microsoft.Net.Compilers</__paket__Microsoft_Net_Compilers_props>
      </PropertyGroup>
    </When>
  </Choose>
  <Import Project="..\packages\Microsoft.Net.Compilers\build\$(__paket__Microsoft_Net_Compilers_props).props" Condition="Exists('..\packages\Microsoft.Net.Compilers\build\$(__paket__Microsoft_Net_Compilers_props).props')" Label="Paket" />
  <Choose>
    <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3')">
      <PropertyGroup>
        <__paket__Microsoft_CodeDom_Providers_DotNetCompilerPlatform_props>Microsoft.CodeDom.Providers.DotNetCompilerPlatform</__paket__Microsoft_CodeDom_Providers_DotNetCompilerPlatform_props>
      </PropertyGroup>
    </When>
  </Choose>
  <Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\build\$(__paket__Microsoft_CodeDom_Providers_DotNetCompilerPlatform_props).props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\build\$(__paket__Microsoft_CodeDom_Providers_DotNetCompilerPlatform_props).props')" Label="Paket" />
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

It should be changed to:

  <Import Project="..\packages\Microsoft.Net.Compilers\build\$(__paket__Microsoft_Net_Compilers_props).props" Condition="Exists('..\packages\Microsoft.Net.Compilers\build\$(__paket__Microsoft_Net_Compilers_props).props')" Label="Paket" />
  <Choose>
    <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3')">
      <PropertyGroup>
        <__paket__Microsoft_Net_Compilers_props>Microsoft.Net.Compilers</__paket__Microsoft_Net_Compilers_props>
      </PropertyGroup>
    </When>
  </Choose>
  <Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\build\$(__paket__Microsoft_CodeDom_Providers_DotNetCompilerPlatform_props).props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\build\$(__paket__Microsoft_CodeDom_Providers_DotNetCompilerPlatform_props).props')" Label="Paket" />
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
  <Choose>
    <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3')">
      <PropertyGroup>
        <__paket__Microsoft_CodeDom_Providers_DotNetCompilerPlatform_props>Microsoft.CodeDom.Providers.DotNetCompilerPlatform</__paket__Microsoft_CodeDom_Providers_DotNetCompilerPlatform_props>
      </PropertyGroup>
    </When>
  </Choose>

As you can see, the order of the <Import> and <Choose> tags has been changed. This will allow the project to be compiled again.

Expected behavior

<Choose> tags should be emitted after the <Import> tags of the package.

Actual behavior

<Choose> tags should is emitted before the <Import> tags of the package.

Known workarounds

The only workaround is to patch the .csproj by hand.

Related information

This issue exists for a few weeks now. It’s still in 3.16.2.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
isaacabrahamcommented, Jan 26, 2017

Hmmm. I’ve just run into the same problem now though - clean ASP .NET project, convert-from-nuget.

0reactions
enricosadacommented, Jan 24, 2018

Closing

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript compiles fine, but emitted JavaScript import fails
I've tried that, the ts file compiles fine, but then I get the following error on the browser: "Uncaught TypeError: Error resolving module...
Read more >
Used import elided from emit where source is JavaScript
I would expect to see export = TruffleContract and declare function TruffleContract(param: type): type in definitions.
Read more >
TSConfig Reference - Docs on every TSConfig option
Note that this feature does not change how import paths are emitted by tsc , so paths should only be used to inform...
Read more >
TypeScript: Documentation - Modules
Syntax: What syntax do I want to use to import and export things? Module Resolution: What is the relationship between module names (or...
Read more >
How to Import a Car
Find out if your imported car is exempt from emissions testing and restrictions. Import restrictions. The U.S. government prohibits the importation of vehicles ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found