Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

*.targets cannot be imported again. It was already imported

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

like image 224
dnf Avatar asked Aug 30 '17 14:08

dnf


3 Answers

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.

like image 128
Leo Liu-MSFT Avatar answered Oct 26 '22 23:10

Leo Liu-MSFT


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

like image 44
Mirco Avatar answered Oct 26 '22 23:10

Mirco


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" />
like image 31
Dmitri K Avatar answered Oct 26 '22 22:10

Dmitri K