*.targets cannot be imported again. It was already imported
Asked Answered
M

7

9

I have UWP app build in VS 2017 and many project in my solution have build warning like below. How to get rid of them?

Warning "C:\Program Files (x86)\MSBuild\15.0.Net\CoreRuntime\Microsoft.Net.CoreRuntime.targets" cannot be imported again. It was already imported at "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Microsoft.Common.targets\ImportAfter\Microsoft.Net.CoreRuntime.ImportAfter.targets (17,3)". This is most likely a build authoring error. This subsequent import will be ignored. [D:\Projects\HA4IoT\Controllers\HA4IoT.Controller\HA4IoT.Service.csproj] HA4IoT.Tests
Warning "C:\Program Files (x86)\MSBuild\15.0.Net\CoreRuntime\Microsoft.Net.CoreRuntime.Settings.targets" cannot be imported again. It was already imported at "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Microsoft.Common.targets\ImportBefore\Microsoft.Net.CoreRuntime.ImportBefore.targets (17,3)". This is most likely a build authoring error. This subsequent import will be ignored. [D:\Projects\HA4IoT\DNF\HA4IoT.Extensions.Tests\HA4IoT.Extensions.Tests.csproj] HA4IoT.Controller.Dnf
Warning "C:\Users\dnf.nuget\packages\microsoft.net.native.compiler\1.6.3\tools\Microsoft.NetNative.targets" cannot be imported again. It was already imported at "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Microsoft.Common.targets\ImportAfter\Microsoft.NetNative.ImportAfter.targets (16,3)". This is most likely a build authoring error. This subsequent import will be ignored. [D:\Projects\HA4IoT\Controllers\Examples\HA4IoT.Controller.Main\HA4IoT.Controller.Main.csproj] HA4IoT.Controller.Main

Megathere answered 30/8, 2017 at 14:13 Comment(4)
Are you running the last version of VS 2017 e.g. 15.3 or 15.4 if preview? AFAIK this issue has been resolved before RTM. Also you may try repairing VS.Superorder
I have done clean and rebuild on both VS 2017 15.3.3 and 15.4, also done clean instal of 15.3.3 but warnings are still thereMegathere
This is because of the cs file created in older version and then migrated to VS 2017. I had the same issue. All i did was create a new Solution in VS 2017, add nuget packages and edit the cs file to match the new cs file created in vs 2017. Pretty hacky but does the job.Darnell
I think you are talking about csproj not cs? I'm not sure what you were aditing in those file? You have added new projects and move files to them or update something specific in old files?Megathere
P
17

How to get rid of them?

I found the work-around of this question on MSDN:

Using condition to check the existence of a unique property defined in the considering project file.

<PropertyGroup>
  <TasksTargetsImported>true</TasksTargetsImpor‌​ted>
</PropertyGroup>

<Import Project="Tasks.targets" Condition=" '$(TasksTargetsImported)' == '' "/> 

Hope this can helps.

Pneumectomy answered 31/8, 2017 at 10:11 Comment(0)
K
7

I removed all nuget target and prop files next to the .csproj files. This worked for me. All warnings are now gone.

Knepper answered 6/9, 2017 at 9:3 Comment(1)
I got the warnings after updating the Target and Min Versions, so my guess is that the .target and .prop files once had to be in the project, but got factored out later on into the build system.Chaing
E
4

Unload project or edit project solution file then check entire project file and make sure the same line is not repeated twice. In my case after I followed Web.config transformation instructions I added an extra line like the one below by mistake. You just want to make sure you have no dupes.

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" />
Economy answered 22/9, 2020 at 13:29 Comment(0)
M
2

I got this issue using the CLI tools after updating VS2017,

The fix was to simply delete the bin/obj folders, not modifying the targets file

Monkish answered 10/2, 2019 at 3:41 Comment(2)
VS2022 - .NET MAUI project - this worked like a charmVentricular
This is what worked for me too.Lewak
D
0

I had the error "\PrefixFidelity\obj\PrefixFidelity.csproj.nuget.g.props(16,5): warning MSB4011: "..."This is most likely a build authoring error. This subsequent import will be ignored."

trace it to a second props file in the obj folder: PrefixFidelity.csproj.nuget.g.(2)props

once that file was deleted the error was gone

Degeneracy answered 26/4, 2018 at 15:36 Comment(1)
Welcome to Stackoverflow! Please format your post to make it more readable (Bold, italic, list , code indentation etc)Serviceman
B
0

I ran into this problem after importing an azure publish profile. My .csproj was updated from:

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

to:

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

Reverting that change removes the warning and the publish process still works ok. I'm using visual studio 2019, this is an Azure Functions project, targeting .net core 3.1.

Bedridden answered 11/11, 2021 at 15:42 Comment(0)
F
0

My fix was the following:

  1. Open Project in VS
  2. Menu Tools/Nuget Package Manager/Package Manager Console
  3. Type the command at the prompt PM> Update-Package -reinstall
Friendship answered 12/5, 2023 at 23:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.