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.

Importing custom targets does not work with .NET Core & Paket 4.X

See original GitHub issue

Description

We have a NuGet package with a build target inside it which we use to enforce our “build police” (checking for things like namespace prefix and other things). I can see that paket is not adding the targets reference into the csproj file.

paket.dependencies:

source http://nuget.geniussports.net/NugetWebFeed/nuget

nuget GeniusSports.Common.Targets import_targets: true

nuget System.Net.NetworkInformation ~> 4.0
nuget Newtonsoft.Json ~> 9.0

paket.references

GeniusSports.Common.Targets import_targets: true

Newtonsoft.Json
System.Net.NetworkInformation

Repro steps

Please provide the steps required to reproduce the problem

See attached ZIP. I have also attached our target nuget package.

PaketRepro.zip

GeniusSports.Common.Targets.1.0.2.nupkg.zip

Expected behavior

This is added to the csproj:

  <Import Project="..\packages\MSBuildTasks\build\MSBuildTasks.targets" />
  <Import Project="..\packages\GeniusSports.Common.Targets\build\GeniusSports.Common.targets" />

Actual behavior

No build targets are added.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:29 (26 by maintainers)

github_iconTop GitHub Comments

1reaction
cjbhainescommented, May 14, 2017

Ah sorry I didn’t realise that, I thought they had just move the references into obj. I can now see this in my obj g.targets file:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
  </PropertyGroup>
  <ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
    <Import Project="$(NuGetPackageRoot)msbuildtasks\1.5.0.235\build\MSBuildTasks.targets" Condition="Exists('$(NuGetPackageRoot)msbuildtasks\1.5.0.235\build\MSBuildTasks.targets')" />
    <Import Project="$(NuGetPackageRoot)microsoft.vssdk.buildtools\15.0.26201\build\Microsoft.VSSDK.BuildTools.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.vssdk.buildtools\15.0.26201\build\Microsoft.VSSDK.BuildTools.targets')" />
  </ImportGroup>
</Project>

So that has imported the MS packages fine. Interestingly I still can’t get it to import my custom targets:

paket.dependencies:

source http://nuget.geniussports.net/NugetWebFeed/nuget

nuget GeniusSports.Common.Targets


source https://www.nuget.org/api/v2

nuget Microsoft.VSSDK.BuildTools
nuget MSBuildTasks

paket.references:

GeniusSports.Common.Targets import_targets: true
Microsoft.VSSDK.BuildTools import_targets: true
MSBuildTasks import_targets: true

Comparing my package to the MSBuildTasks packages it looks like everything is fine:

geniussports common targets

msbuildtasks

I have tried:

  • paket update
  • paket install
  • dotnet restore

All without luck. I can see that the dependency has been added to the obj references file:

GeniusSports.Common.Targets,2.0.0,Direct
Microsoft.VSSDK.BuildTools,15.0.26201,Direct
MSBuildTasks,1.5.0.235,Direct

But nothing has been added to the g.targets file for the Genius Sports targets. Hopefully I’m not doing something silly here.

I have attached our targets package for reference as well.

GeniusSports.Common.Targets.2.0.0.nupkg.zip

0reactions
cjbhainescommented, May 14, 2017

and queue the “it was the being silly part” music! 😃 Thanks for your help! I will test this when I’m back in the office on Monday and report back

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding .targets file to .NET framework nuget won't import ...
I have a project that I import RawDataConverter.nuget into (GeoApp). The framework type for GeoApp is .NET Core 2.1. I've never had an...
Read more >
PackageReference in project files - NuGet
Package references, using <PackageReference> MSBuild items, specify NuGet package dependencies directly within project files, as opposed to ...
Read more >
Paket and the .NET SDK / .NET Core CLI tools (dotnet CLI ...
The general workflow is not very different from using Paket with traditional .NET projects which it is described in the "Getting started" tutorial....
Read more >
prometheus-net 8.0.1
This library allows you to instrument your code with custom metrics and provides some built-in metric collection integrations for ASP.NET Core.
Read more >
Consume NuGet packages | JetBrains Rider Documentation
To find a NuGet package, use the search field and the list of Available packages, which appears under the list of Installed packages....
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