Error MSB4061: The "XamlCTask" task could not be instantiated - visual-studio

While trying to compile a Xamarin Forms (2.3.4.247) project on Visual Studio for Mac Community (7.0.1 [build 24]) I keep getting the two following errors after coding some time, any clue on what caused it and how to fix it?
/Users/PathToProjectRoot/packages/Xamarin.Forms.2.3.4.247/build/portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20/Xamarin.Forms.targets(3,3): Error MSB4061: The "XamlCTask" task could not be instantiated from "/Users/PathToProjectRoot/packages/Xamarin.Forms.2.3.4.247/build/portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20/Xamarin.Forms.Build.Tasks.dll". Could not load file or assembly 'Xamarin.Forms.Build.Tasks' or one of its dependencies (MSB4061) (ProjectName)
/Users/PathToProjectRoot/packages/Xamarin.Forms.2.3.4.247/build/portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20/Xamarin.Forms.targets(3,3): Error MSB4060: The "XamlCTask" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name. (MSB4060) (ProjectName)
What I have tried
Updated all packages and and SDKs.
Cleaned/Rebuild solution.
Removed all packages, closed VS, reopened and got all packages restored.
Removed all the bin and obj folders to try a rebuild.
Check the 3 .csproj for any outdated imports previous to 2.3.4.247.
Create a new solution.
What has worked
Creating a new clean solution using Xamarin Forms works however this causes all the packages to be from an old version. I've already done this twice but I'd like to be able to stop doing this as it takes a crazy amount of time to transfer all files from the broken project to the new one.
What hasn't worked
Besides all the things I've tried, it may be useful to mention that creating a new project after having cleared all the previous ones within the same solution doesn't fix the issue.
This makes me think that it is a solution-level error rather than a project-level error.
What packages are installed
Xamarin.Android.Support.Animated.Vector.Drawable.25.3.1
Xamarin.Android.Support.Annotations.25.3.1
Xamarin.Android.Support.Compat.25.3.1
Xamarin.Android.Support.Core.UI.25.3.1
Xamarin.Android.Support.Core.Utils.25.3.1
Xamarin.Android.Support.Design.25.3.1
Xamarin.Android.Support.Fragment.25.3.1
Xamarin.Android.Support.Media.Compat.25.3.1
Xamarin.Android.Support.Transition.25.3.1
Xamarin.Android.Support.Vector.Drawable.25.3.1
Xamarin.Android.Support.v4.25.3.1
Xamarin.Android.Support.v7.AppCompat.25.3.1
Xamarin.Android.Support.v7.CardView.25.3.1
Xamarin.Android.Support.v7.MediaRouter.25.3.1
Xamarin.Android.Support.v7.Palette.25.3.1
Xamarin.Android.Support.v7.RecyclerView.25.3.1
Xamarin.Build.Download.0.4.5
Xamarin.Forms.2.3.4.247
What Android platforms are installed
android-23
android-25
What file causes the errors
Error is caused by the file Xamarin.Forms.targets containing the following lines:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="Xamarin.Forms.Build.Tasks.XamlGTask" AssemblyFile="Xamarin.Forms.Build.Tasks.dll"/>
<UsingTask TaskName="Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName" AssemblyFile="Xamarin.Forms.Build.Tasks.dll"/>
<UsingTask TaskName="Xamarin.Forms.Build.Tasks.XamlCTask" AssemblyFile="Xamarin.Forms.Build.Tasks.dll"/>
<!-- Some more lines here ... -->
<Target Name="XamlC">
<!-- /!\ Error flagged at next line's "<" -->
<XamlCTask
Assembly = "$(IntermediateOutputPath)$(TargetFileName)"
ReferencePath = "#(ReferencePath)"
Verbosity = "2"
OptimizeIL = "true"
DebugSymbols = "$(DebugSymbols)"
DebugType = "$(DebugType)"/>
</Target>
</Project>
Latest updates
[June 16]
After trying to create a new solution several times, I'm now unable to create one that's able to build. Whatever version my packages are on, I keep getting those two errors.
See the Build output here.

This issue was caused by the # character within the project's path. Removing it resolved the issue.

Wired ... But closing visual studio and reopen solved the problem in my case

I had the same issue, it was caused by C:\User\name\.nuget folder being a symbolic link (created with MKLINK), which pointed to a directory on a bigger drive. When I set NUGET_PACKAGE environment variable to the actual location of the package directory, the issue is solved.

I was facing a similar issue like yours. I updated many dependencies and removed a few.
I'm using this version of VS
I tried all the answers and didn't work.
I followed the "Just In Case" approach (mentioned in this answer thread previously.) of killing the VS instance and reopening it. Then when I executed the project all errors vanished.

In my case, I didnt have # in the path and I tried clean and rebuild,deleting obj,bin,packages folders, closed and opened many times etc but didnt work.
My nuget packages folder is referenced at this path 'C:/Users/xyz/.nuget/packages/'
I tried to change the path of this nuget packages folder using a nuget.config file and placed it in the solution folder as specified in the below link and it worked.
Is it possible to change the location of packages for NuGet?
For me this piece of code worked among all the answers in the above link.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value="C:\Projects\MyProj\.nuget\packages" />
<add key="repositoryPath" value="C:\Projects\MyProj\.nuget\packages" />
</config>
</configuration>

Related

Error NU1105 Unable to find project information - The project file may be invalid or missing targets required for restore

All of a sudden, I am getting the following errors for 3 projects in a solution:
Error NU1105 Unable to find project information for 'C:\code\example\src\libs\example.I18n\example.I18n.csproj'.
The project file may be invalid or missing targets required for restore.
The only thing that has changed in the project is a couple of DB changes, but I never had any issues in the past. The only other thing is that I updated to Visual Studio 2017 15.5. Could that cause issues?
I have tried removing and recloning the solution from source control, but still getting errors. No problems on my colleagues' machines, so it must be something local.
Example of one of the .csproj files if this helps:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<AssemblyName>Example.I18n</AssemblyName>
<PackageId>Example.I18n</PackageId>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
<PackageReference Include="MessageFormat" Version="1.0.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
I also got the same after upgrading to version 15.6 of Visual Studio 2017.
Closing VS and deleting the .vs folder fixed it for me.
For me, the casing of the project file on disk did not match the casing in the solution file.
Say I had a solution with LibraryA.csproj and LibraryB.csproj, where LibraryB.csproj has a reference to LibraryA.csproj. Having an incorrect casing for LibraryA.csproj in the solution file would cause NU1105 when building LibraryB.csproj:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryA", "LibraryA\Librarya.csproj", "{24DEBB3B-762A-491D-8B83-6D078C0B30C0}"
I started seeing this problem after upgrading to version 15.5 of Visual Studio 2017. I did not encounter this problem with version 15.4.5.
I had this problem and I just followed what the error message recommends inside VS:
to restore the solution.
So I opened a command line or package manager console, chdir into the directory with the solution (.sln) file and just issued
C:> dotnet restore .\mySolution.sln
Problem was fixed.
This error message will also occur if a referenced project is not included in the solution. I encountered this problem today, and I found the fix here.
I encountered this error when having a duplicate reference to a project.
<ProjectReference Include="..\ProjectA.csproj" />
<ProjectReference Include="..\ProjectA.csproj" />
Removing the duplicate reference resolved the error.
What worked for me was to
Remove the offending project
Build the solution
Re-add the project.
Seems that some projects were removed from solution file (don't know why). Fixed by undoing these solution file changes
I have next project structure (.Net Core projects):
../classLib
../../../webProject1
../../../webProject2
../../myWebProjects.sln
webProject1 and webProject2 reference classLib as project itself (not as .dll). When I opened my solution in VS 2019 and tried to build I got identical error NU1105: Unable to find project information for '../classLib.csproj'. error.
Before build depended projects you need to restore there dependency. What I did, just add
next Target to my webProject1.csproj and webProject2.csprojfiles.
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="dotnet restore" />
</Target>
Open powershell and running restore command solved my issue.
dotnet restore Sample.sln
I correct this error by simply running the clean solution option.
Right click the solution in the solution explorer and choose clean solution.
This is insane, i tried all this:
updated VS. manually deleted all bin folders, run dotnet restore, clean rebuild nothing works
solution: finally i unload all the projects and start reloading them into solution, one by one in the order they show dependency errors. then the last one just cascade fixes everything. No idea what was wrong
I recently came across Error NU1105 while using JetBrains Rider on Linux. So this involves Mono and the MSBuild version that comes with it.
It turns out this was being caused by my solution files being in a directory that was a symbolic link to another directory. I believe MSBuild was dereferencing the linked directory and instead referencing the source directory. This makes some of the referenced paths completely different, even though they are the exact same files, case, everything else. Opening the solution from the original location works perfectly now for me.
Reload the project which causes the problem, this will fix the issue,
As mentioned in the following link :
https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1105
This happend to me when I had files with names exceeding OS's max path limit. Check your names ;)
In my case I did it and it worked for me
goto Tools/CommandLine/Developer Command Prompt or Developer Powershell
type this command and Enter "dotnet restore".
Build your solution
That's all
Just use: "dotnet restore MySolution.sln",
Where MySolution.sln is your solution.
I was getting this error error NU1105: Unable to find project information for 'C:\folder2\project1.csproj'.
but project1 that I had as part of the solution was located in C:\folder1\project1.csproj (it was also there in c:\folder2\project1.csproj too but not part of the solution, so it was confusing)
Once I changed the reference to the correct location of the project it worked.
After spending 3 hours, trying out numerous solutions, what worked for me is that I had to undo my root solution sln file...some of the project references were removed..not sure how.

How can I fix missing nuget references after moving project in Visual Studio 2015

I had a project structure like this:
WebApp
-- WebApp
-- WebApp.sln
WebApp.Tests
-- WebApp.Tests.csproj
I moved WebApp.Tests into WebApp using a move (simple click & drag into the WebApp folder). I edited WebApp.sln to fix the project reference so that it will load.
When I build, Nuget complains that packages are missing and to do a restore.
I downloaded and used nuget.exe restore on my solution and it reported everything was there.
Based on other Stack Overflow answers, I have tried the following:
Edit the test project reference hint paths. I changed from ..\WebApp\packages\PACKAGE to ..\packages\PACKAGE
Reload Visual Studio (multiple times)
Delete contents of packages folder and bin/obj folders of the projects
Use the package manager console to reinstall packages on the Test Project
All of these failed to fix the problem. When I used the package manager to try to reinstall the packages with the command, it gave me the same error that project building does - I must restore the packages first.
Is there any quick way to fix my project? I really don't want to go through each package and uninstall/reinstall manually. Also, how could I have prevented this problem in the first place? Is there a built-in way to move project locations?
There was XML similar to this at the end of my project file:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\WebApp\packages\SPECIFICPACKAGE')" Text="$([System.String]::Format('$(ErrorText)', '..\WebApp\packages\SPECIFICPACKAGE'))" />
</Target>
By changing the ..\Webapp\packages to ..\packages like the rest of the file, my solution compiles just fine now.
I had the same issue where I physically moved a project folder into the src folder and got the missing packages error. My fix was to open up the .csproj file in notepad and replace every instance of
this:
..\packages\
with this:
..\..\packages\
It solved the issue...

VisualStudioVersion="VersionLatest" is not being picked up

I've created an MSBuild proj file that contains the following header:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0" TargetFrameworkVersion="4.5" VisualStudioVersion="VersionLatest">
This proj file is used to trigger an MSBuild on a number of SSDT projects, couples with a Deploy.
For most developers, this is fine. However, one dev encounters a Deploy72002 exception when trying to run the build. According to this answer, this is due to the VisualStudioVersion not being set. Sure enough, adding
set VisualStudioVersion="12.0"
in the batch file prior to the MSBuild call fixes the problem.
However, I was under the impression (I can't find the source now) that setting VisualStudioVersion="VersionLatest" in the xml of the proj file was sufficient to make it use the highest version of VS installed. I've even tried setting it from VersionLatest to 12.0, and also moving it from the root node, into a node of it's own in <PropertyGroup>.
I'd rather not have a hardcoded reference to 12.0 in the batch file. Am I missing something obvious to make VersionLatest work?
Try this: run MsBuild with the command line option to generate a preprocessed single file. Do the same on a working computer with the same version. Diff the files produced.
It might be picking up different contents for some .props or .targets file. These have been known to change due to installing or updating some or another. I recall following a msdn article to fix such a file when I looked up a problem.

Cannot load WiX projects after installing the VS2010 Web Publishing Updates

I installed the VS2010 web publishing updates yesterday, and now whenever I try to load a WiX setup project (all showing as unloaded in solution explorer) I'm getting the error:
The imported project "PROJECTNAME.wpp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.5\Web\Microsoft.Web.Publishing.targets
Where PROJECTNAME is the path to my setup wixproj file, without the .wixproj extension. I've checked through the project file and there is no reference to a wpp.targets file anywhere. I decided to try and create a blank targets file in that location and so added one with just this in it:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
But got exactly the same error - a not found exception despite the file being there!
I then dug into the Microsoft.Web.Publishing.targets file and had a look for any ".wpp.targets" text, which gave me this:
<PropertyGroup Condition="'$(EnableWebPublishProfileFile)'=='true' And
'$(WebPublishProfileFile)' != '' And Exists($(WebPublishProfileFile)) ">
<WebPublishProfileCustomizeTargetFile Condition="'$(WebPublishProfileCustomizeTargetFile)'==''">
$([System.IO.Path]::ChangeExtension($(WebPublishProfileFile), '.wpp.targets'))
</WebPublishProfileCustomizeTargetFile>
...
So that looks to be setting up a filename of PROJECTNAME.wpp.targets, but only when the EnableWebPublishProfileFile property is set to true. I added this to my wixproj file's main propertygroup:
<EnableWebPublishProfileFile>False</EnableWebPublishProfileFile>
Again though, it made no difference at all to the error. I'm running out of ideas here now!
Further update
I've been trying to repo this on a blank project (so far without success), and the messing about has narrowed the error down to this line (186) in the Microsoft.Web.Publishing.targets file:
<Import Project="$(WebPublishPipelineCustomizeTargetFile)"
Condition="'$(WebPublishPipelineCustomizeTargetFile)' != ''"/>
This is set at the top of the file:
<WebPublishPipelineCustomizeTargetFile
Condition="'$(WebPublishPipelineCustomizeTargetFile)'==''">
$(WebPublishPipelineProjectDirectory)\*.wpp.targets
</WebPublishPipelineCustomizeTargetFile>
I'm not sure how this is getting changed to PROJECTNAME.wpp.targets though?
I tried overriding this in my project file, but once again, it makes no difference at all.
Next I added an Exists() condition to the line in the targets file, now some projects are working and others are not, instead failing (on build) with the error:
The "DisableEscapeMSBuildVariable" parameter is not supported by the "ImportParametersFile" task. Verify the parameter exists on the task, and it is a settable public instance property.
My journey continues...
I experienced the same issue when trying to open a standard web project.
The proj file was referencing the following import for v10.0 targets but throwing the import error in the question which referred to v10.5 targets.
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />
The same was true when I referenced a hard coded path - I still got v10.5 error
My solution was to simply back up and remove that version located at:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\10.5
I'm really not sure what other programs and projects need this version or why import paths were not followed but it go this project open for me seeming falling back to the correct version.

remove nuget package restore from solution

I added the recent nuget package restore feature to a solution using 'Enable NuGet Package Restore':
http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages
However it broke my build server and I didn't have the time to fix it, so I wanted to remove it. There's no option for that as far as I know, so I removed the following line manually from all my *.csproj files:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
The problem now is that every time my *.csproj files are checked out or open my solution, the line is automatically added again, breaking my build if I accidentally check it in :(
Any ideas how I can remove it permanently?
UPDATE: despite the answer below it still keeps coming back when opening the solution, anyone with the same problem?
I didn't look very well, there's another property added to the project files:
<RestorePackages>true</RestorePackages>
Just have to remove this as well as all these lines manually from all *.csproj files:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
UPDATE:
Turns out it's a persistent little bugger, if you're manually editing your project files, make sure to close the solution and delete all the lines from the project at once, otherwise they're just added again once the project reloads...
UPDATE2:
Delete the .nuget folder from the solution root too
UPDATE3:
A later version of NuGet adds another section that you need to remove:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
Update4
Inside the NuGet.Targets located in the .nuget folder, there is another section that gets added to new projects... switch it to false.
<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'false'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>
To disable Nuget Package Restore:
Delete .nuget folder
Remove specific lines from all .csproj files
Lines to remove:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<RestorePackages>true</RestorePackages>
Note: Make sure you do all changes in one go before reloading solution or else it will add them back.
This is based on the following article:
http://bartwullems.blogspot.no/2012/08/disable-nuget-package-restore.html
Also, you might want to double-check that this option is disabled:
http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages
Isn't it this setting here?
Options... -> Nuget Package Manager -> [uncheck] Allow Nuget to download missing packages
I'm using Visual Studio Professional + Resharper 8.2
Solutions currently using MSBuild-Integrated package restore can be migrated to Automatic Package Restore. From what I understand, this should help those who are encountering CI build issues. (Please correct me if I am mistaken).
Please refer to the document on the nuget website: Migrating MSBuild-Integrated solutions to use Automatic Package Restore at http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore
There is information there for converting with and without TFS.
David Ebbo also posted some information at http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html
We actually have a blog post about it and at the end of the post a powershell script was mentioned to help with the migration.
http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore
NuGet has a blog post about migrating to automatic package restore:
http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore
There is a powershell script referenced in the blog post that will take care of removing the necessary lines automatically (and recursively):
https://github.com/owen2/AutomaticPackageRestoreMigrationScript/blob/master/migrateToAutomaticPackageRestore.ps1
Offering a Disable NuGet Package Restore option directly is marked as Won't Fix:
https://nuget.codeplex.com/workitem/1883
I had the same issue. What I ended up doing:
1) go into each project .csproj file in the solution, open it in notepad then removed the portion of the xml and saved.
2)Then I removed the all of the package.config files in the entire solution.
3)Then I had to remove the .nuget and package folders.
At this point, I had a completely NuGet free solution.
4)Then I manually referenced any needed DLLs and hit compile and the solution ran like a champ without the NuGet packages being needed.
I followed the accepted solution to no avail using 2012. This did work though,
Completely close the VS
Update the <RestorePackages>true</RestorePackages> to <RestorePackages>false</RestorePackages> and delete the <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> line
Also renamed the nuget.exe to nuget.exe.NotExe
For anyone still needing to clean up a project using the old style NuGet package restore, the IFix tool available here automates the process.
Just run the installer (IFix will be added to PATH) and then run the following:
IFix nugetrestore --fix
You can run it in check mode first to see what it will clean up:
IFix nugetrestore --check
Go to your solution directory where you have [$(SolutionDir)\.nuget\nuget.targets]
.nuget folder and nuget.targets file under it delete the folder,
and change remove lines from your csproj for once last time.
The problem won't come back to bug you again.
Remove the packages.config file within your solution.
I accidentally enabled this "package restore" option while opening my project in VS2012 RC and started getting errors that looked something like:
"Error 1 Unable to locate 'C:\FolderX\SomeProject.nuget\nuget.exe'"
To fix the error I followed the above instructions, opened open each project file in notepad and removed that RestorePackage line.
I was able to resolve this issue by taking these steps:
1) make sure you take a backup of all your current checked-out files changes.
2) physically delete the solution folder from your C:\ (path that is mapped to TFS).
3) get latest from TFS for your solution.
4) copy (if any) your changes from the backup you took in step-1.
hope that helps !
I ran into the exact same problem and tried to remove all .nuget and RestorePackage tags from the project files but one project just wouldn't reload not matter how thoroughly I examined it for .nuget and RestorePackages tags. I guess there's some hidden references to this somewhere.
In the end it was easier to just copy the files and create a new project and import it to the solution.
Nuget sucks. Just remove nugets and remove or comment package elements from packages.config in root directory of the projects where this is a problem. Use direct references into some lib folder instead.
<?xml version="1.0" encoding="utf-8"?>
<packages>
<!--<package id="EntityFramework" version="6.0.2" targetFramework="net45" />-->
</packages>

Resources