Visual Studio cannot find any references for a new project - c#

This is a weird one.
I have Visual Studio 2013 installed. If I create a new project, Visual Studio immediately complains that it cannot find any of the references:
The project does however compile and run correctly, even though there are warnings in the error list:
If I look at the properties of any of these references, their paths are empty. If I load an existing project, Visual Studio can find its references and doesn't complain, even though it is targeting the same version of the .Net framework as the broken project (I've even had them both in the same solution with the same behaviour).
How can I fix this, and what could have caused it? Any suggestions welcome, as it is baffling me.

With thanks to icemanind, I have the answer.
I closed Visual Studio, deleted the following directories and everything is now working as normal again:
C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\12.0
C:\Users\<username>\AppData\Roaming\Microsoft\VisualStudio\12.0

I faced this problem, and I solved it by closing visual studio, reopening visual studio, cleaning and rebuilding the solution. This worked for me. On some other posts, I have read the replies and most of users solved the problem by following this way.
Another possibility is that the target .NET Framework version of the class library is higher than that of the project.

This happens to me from time to time and I always suspect VS corruption, but it always turns out to be user error. It typically happens when I add a new project to a solution and try to reference earlier projects in the newly added project. In this case and in general, you can only add a reference if it targets the same or earlier .NET Framework version. In my case, inconsistent target framework versions caused the project to not recognize references and not allow compilation. Double checking consistency or proper target framework versions solved this problem for me.

I had a problem with an existing project, and by creating a new one and comparing the csproj files I had to add missing import lines like those: one at the beginning of the project element and one at the end.
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
...
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

I recently had this happen in VS 2017. I had done some refactoring on a project where the csproj file had moved, then cloned the repository onto a new machine. The csProj file had multiple locations for the .projects directory. For example:
<Import Project="packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="packages\Microsoft.Net.Compilers.1.2.1\build\Microsoft.Net.Compilers.props" Condition="Exists('packages\Microsoft.Net.Compilers.1.2.1\build\Microsoft.Net.Compilers.props')" />
<Import Project=".\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('.\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project=".\packages\Microsoft.Net.Compilers.1.2.1\build\Microsoft.Net.Compilers.props" Condition="Exists('.\packages\Microsoft.Net.Compilers.1.2.1\build\Microsoft.Net.Compilers.props')" />
There were additional relative path errors below in the Error tags as well.
I looked for any places where I had duplicated, incorrect package relative paths, and removed the incorrect ones.
This caused it to build for me.
Good luck out there!
-Mezz

I had a similar issue with vs2015. It turns out a file was added twice to the .csproj
Deleting the duplicated line solved it

In a most cases you need:
Unload Project
Reload Project with dependecies
Rebuild solution

Related

How to resolve reference issues in Visual Studio [duplicate]

I'm getting a:
type or namespace name could not be found
error for a C# WPF app in VS2010. This area of code was compiling fine, but suddenly I'm getting this error. I've tried removing the Project Reference and the using statement, shutting VS2010 and restarting, but still I have this issue.
Any ideas why this might be occurring, where it seems like I'm doing the right thing re Reference & using statement?
I also noted in VS2010 that intellisense for that namespace is working ok, so it seems like VS2010 has the project reference and is seeing the namespace on one hand, but during compile doesn't see it?
This can be the result of a .Net framework version incompatibility between two projects.
It can happen in two ways:
a client profile project referencing a full framework project; or
an older framework version targeting a newer framework version
For example it will happen when an application is set to target the .Net 4 Client Profile framework, and the project it references targets the full .Net 4 framework.
So to make that clearer:
Project A targets the Client Profile framework
Project A references Project B
Project B targets the full framework
The solution in this case is to either upgrade the framework target of the application (Project A), or downgrade the target of referenced assembly (Project B). It is okay for a full framework app to reference/consume a client profile framework assembly, but not the other way round (client profile cannot reference full framework targeted assembly).
Note that you can also get this error when you create a new project in VS2012 or VS2013 (which uses .Net 4.5 as the default framework) and:
the referencing project(s) use .Net 4.0 (this is common when you have migrated from VS2010 to VS2012 or VS2013 and you then add a new project)
the referenced projects use a greater version i.e. 4.5.1 or 4.5.3 (you've re-targeted your existing projects to the latest version, but VS still creates new projects targeting v4.5, and you then reference those older projects from the new project)
Reinstalling nuget packages did the trick for me. After I changed .NET Framework versions to be in sync for all projects, some of the nuget packages (especially Entity Framework) were still installed for previous versions. This command in Packages Manager Console reinstalls packages for the whole solution:
Update-Package –reinstall
I've no idea why this worked, but I removed the project reference that VS2015 was telling me it couldn't find, and added it again. Solved the problem. I'd tried both cleaning, building and restarting VS to no avail.
When building the solution I was getting the same error (type or namespace ' ' could not be found). Below it I saw a warning stating that "the reference could not be resolved" and to make sure "the assembly exists on disk".
I was very confused, because my DLL was very clearly in the location that the reference was pointing to. VS didn't seem to highlight any errors, until I tried to build the solution.
I finally realized the problem (or at least what I suspect was the problem). I was building the library file in the same solution. So even though it existed on the disk, it was being rebuilt in that location (somehow in the process of the library getting rebuilt my other project - in the same solution - that referenced the library must have decided that the library didn't exist)
When I right-clicked on the project and built that only, instead of the entire solution, I didn't get the error.
To fix this problem I added the library as a dependency to the project that was using it.
To do this:
I right-clicked on my Solution in the Solution Explorer and selected
"Properties"
Then in "Common Properties" I selected "Project Dependencies".
Then in the Projects drop-down menu I selected the project that
relied on the library, and
Checked the box next to the library found under "Depends On"
This ensures that the library project gets built first.
First I would verify that your project's generated information isn't corrupt. Do a clean and rebuild on your solution.
If that doesn't help, one thing I've seen work in the past for designer issues is opening up a windows forms project, then closing it again. This is a little chicken-entrails-ish, though, so don't hold your breath.
A trickier situation I ran into was:
Project one targets the 4.0 full framework with Microsoft.Bcl.Async package installed.
Project two target the 4.0 full framework but would not compile when reference a Project one class.
Once I installed the Async NuGet package on the second project it compiled fine.
In my case, I find the reference in the VisualStudio have a triangle, and a exclamation mark as this image,
then, I right click remove it, and add the dll reference correctly again, the problem was solved.
I had a similar issue: The compiler was unable to detect a folder inside the same project, so a using directive linking to that folder generated an error. In my case, the problem originated from renaming the folder. Even though I updated the namespace of all the classes inside that folder, the project info somehow failed to update. I tried everything: deleting the .suo file and the bin and obj folders, cleaning the solution, reloading the project - nothing helped. I resolved the problem by deleting the folder and the classes inside, creating a new folder and creating new classes in that new folder (simply moving the classes inside the new folder didn't help).
PS: In my case I was working on a web application, but this problem may occur in different types of projects.
This one worked for me. In your class, where the class name is defined, eg: Public class ABC, remove one character and wait a little. You error list will increase because you have changed the name. Now put back the character that you have typed. This worked for me, hopefully it will work for you too. Good Luck!!!
[Facepalm] My issue was that I had added the dependency in the C++ way of doing things.
Go to the project that won't build, open up the 'References' folder in Solution Explorer, and see if your dependency is listed.
If not, you can 'Add Reference' and choose the dependency on the Projects tab.
Boom Shankar.
Check the Build Action of the .cs file containing the missing type. Make sure it's C# compiler.
Click on the .cs file containing the missing type.
Press F4 to bring up Properties.
Make sure Build Action is set to C# compiler.
Before:
After:
It even happens in Visual Studio 2017.
Restart Visual Studio
Clean project that fails to build.
Rebuild the project.
Had the same errors, my story was following:
after bad merging (via git) one of my .csproj files had duplicated compile entries like:
<Compile Include="Clients\Tree.cs" />
<Compile Include="Clients\Car.cs" />
<Compile Include="Clients\Tree.cs" /> //it's a duplicate
If you have a big solution and more than 300 messages in the errors window it's hard to detect this issue.
So I've opened damaged .csproj file via notepad and removed duplicated entries. Worked in my case.
I had same problem as discussed: VS 2017 underlines a class in referenced project as error but the solution builds ok and even intellisense works.
Here is how I managed to solve this issu:
Unload the referenced project
Open .proj file in VS ( i was looking for duplicates as someone suggested here)
Reload project again (I did not change or even save the proj file as I did not have any duplicates)
We had a weird case of this that I just fixed in a solution. There was a hidden/whitespace character in front of a "using" statement in the main project. That project would build fine and the website worked fine, but the unit test project that referenced it could not be built.
I encountered this problem when upgrading existing projects from VS2008 to VS2012. I found that two projects (the only two that I created) were targeting different .Net Frameworks (3.5 and 4.0). I resolved this on the Application tab of the projects by making sure that both projects had ".NET Framework 4" in the Target Framework box.
In my case I had a Class that was listed in the proper source folder, but was not registering in Solution Explorer. I had to do right click the project > Add Existing item and manually select that Class it said it was missing. Then everything worked fine!
I know its old, but I've found the same issue. My project did build, I then updated Visual Studio to the latest & the project wouldnt build as it couldnt find a type definition from a separate assembly. The other assembly built OK, the main project referenced it correctly & nothing had changed since it built OK.
I cleaned the whole solution & rebuilt it, it failed. I built the assembly on its own, it built OK. The project didnt build. I cleaned & built multiple times, and it failed. I then called a colleague to look at it, when I built with him watching, it all built OK.
I think Visual Studio tooling is the problem, especially as I just updated it.
In my case, I unload the project, then:
Opened myProject.csproj and update the ToolsVersion="4.0" to ToolsVersion="12.0"(I'm using vs 2017)(using Paulus's answer https://stackoverflow.com/a/64552201/1594487).
Deleted following lines from the myProject.csproj:
<Import Project="..\packages\EntityFramework.6.4.0\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.0\build\EntityFramework.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
And the problem solved.
You might also try eliminating the code you think you're having problems with and seeing if it compiles with no references to that code. If not, fix things until it compiles again, and then work your suspected problem code back in. Sometimes I get strange errors about classes or methods that I know are correct when the compiler doesn't like something else. Once I fix the thing that it's really getting hung up on, these 'phantom' errors disappear.
I know this is kicking a dead horse but I had this error and the frameworks where fine. My problem was basically stating that an interface could not be found, yet it build and accessed just fine. So I got to thinking: "Why just this interface when others are working fine?"
It ended up that I was actually accessing a service using WCF with an endpoint's interface that was using Entity Version 6 and the rest of the projects were using version 5. Instead of using NuGet I simply copied the nuget packages to a local repository for reuse and listed them differently.
e.g. EntityFramework6.dll versus EntityFramework.dll.
I then added the references to the client project and poof, my error went away. I realize this is an edge case as most people will not mix versions of Entity Framework.
Adding my solution to the mix because it was a bit different and took me a while to figure out.
In my case I added a new class to one project but because my version control bindings weren't set I needed to make the file writable outside of Visual Studio (via the VC). I had cancelled out of the save in Visual Studio but after I made the file writable outside VS I then hit Save All again in VS. This inadvertently caused the new class file to not be saved in the project..however..Intellisense still showed it up as blue and valid in the referencing projects even though when I'd try to recompile the file wasn't found and got the type not found error. Closing and opening Visual Studio still showed the issue (but if I had taken note the class file was missing upon reopening).
Once I realized this, the fix was simple: with the project file set to writeable, readd the missing file to the project. All builds fine now.
I had the same issue. One night my project would compile the next morning ERRORS!.
I eventually found out that visual studio decided to "tweak" some of my references and point them elsewhere. for example:
System.ComponentModel.ISupportInitialize somehow became "blahblah.System.ComponentModel.ISupportInitialize"
Quite a rude thing for vs to do if you as me
My case was same as discussed here but nothing solved it until I've removed the System.Core reference from the references list (Everything worked fine without it)
hope it will help someone because this issue is quite frustrating
To solve this issue it can also help to delete and recreate the *.sln.DotSettings file of the associated solution.
Ok, years later using VS 2017 .NET Core 2.2 Razor Pages I feel this answer might help someone.
If it was a snake it would have bit me.
I was throwing stuff around, changing names, renaming Models, and all of a sudden I got this error:
Error CS0246 The type or namespace name 'UploadFileModel' could not be
found (are you missing a using directive or an assembly reference?)
This was underlined in red in my .chstml Razor Page. (not underlined after fix):
#page
#model UploadFileModel
So, finally, and luckily, I found the code from someone else that I had originally used, and low and behold, the namespace did not include the .cshtml file name!!!
Here is my bad dummy error spank myself with the page name in the namespace:
namespace OESAC.Pages.UploadFile
{
public class UploadFileModel : PageModel
{
What my original code had and all I had to do was delete the page name from the namespace, UploadFile:
namespace OESAC.Pages
{
public class UploadFileModel : PageModel
{
And low and behold, all the errors disappeared!!
Silly me. But you know, MS has made this .NET C# MVC stuff really confusing for us non-computer scientists. I am constantly tripping on my shoelaces trying to figure out model names, page names, and syntax to use them. It shouldn't be this hard. Oh well. I hope error and solution helps someone. The error was right, there is no Namespace named "UploadFileModel" haha.
In my case the problem was that after changing namespace to exactly same as is in another project (intentionally), the name of assembly was changed as well by VS, so there were two assemblies with same name, one overriding the other
Had the same problem after merging some new code into a vs2019 project.
Restarted VS, unloaded and reloaded projects, ensured all projects in solution had same ToolsVersion= and TargetFrameworkVersion. None of this helped.
I had a case of project Substrate, failing to find namespace Skin (in project Skin).
Finally I opened up Substrate.csproj and checked all the ProjectReference Include entries. The others were there, but no reference to Skin, even though Skin did show up in the check box of the little project dependencies dialog. So the project dependencies dialog took the check box for Skin (and saved it somewhere) but did not alter Substrate.csproj. I then added the ProjectReference Include manually, ensuring I had the correct path and GUID for the skin project.
<ProjectReference Include="..\Skin\Skin.csproj">
<Project>{1ad4b5d7-5014-4f5f-983e-2c59ac0e0028}</Project>
<Name>Skin</Name>
</ProjectReference>
I then saved the Substrate.csproj and the problem was solved. So as others have said this is a problem with VS tooling
In my case I had a file built by external dependency (xsd2code) and somehow its designer.cs files were not processed by VS correctly. Creating a new file in Visual Studio and pasting the code in it did the trick for me.
To anyone that is getting this error when they try to publish their website to Azure, none of the promising-looking solutions above helped me. I was in the same boat - my solution built fine on its own. I ended up having to
Remove all nuget packages in my solution.
Close and reopen my solution.
Re-add all the nuget packages.
A little painful but was the only way I could get my website to publish to Azure.

csproj keeps losing referenced project references in VS2017 using new csproj format

My csproj has the following lines:
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<Deterministic>False</Deterministic>
<ItemGroup>
<ProjectReference Include="..\blah.Common\blah.Common.csproj" />
<ProjectReference Include="..\blah.Model\blah.Model.csproj" />
</ItemGroup>
The referenced projects build fine. However in the VS tree these two projects randomly disappear from the Dependencies tree and VS reports the references as missing and the build passes.
Reloading/rebuilding/cleaning/restarting/removing then adding the projects again in no particular order usually fixes it. Problem comes back after a legitimate build error crops up in another project.
I am using Resharper and VS2017
I have tried dotnet restore with no luck. Any ideas why this one particular project is constantly losing its references?
Edit: I just realised I incorrectly mentioned the build as FAILING. It does not fail and builds successfully, however my project is litered with red errors and warnings saying references are missing. After a successful build the red warnings/errors disappear then randomly come back again.
Sometimes the projects are literally missing from the references tree, other times they are visible. When right clicking "add reference" the project is already ticked however. Unloading the project and reloading or doing a full rebuild fixes the "Error" only for it to come back at some point.
Even though the "Error List" is filled with missing reference errors, a clean and full build produces no errors and creates a successful build.
Did you check the .NET framework version that these 3 projects are targeting?
Incompatibility between framework versions allows the reference to get added but results in missing references during build/run time. To validate if this is indeed the problem, you can check the warnings that Visual Studio produces while building the solution. An alternative way of finding the root cause of the problem, would be to add one of the projects as a DLL reference while keeping the other as a project reference. If the DLL reference doesn't work, it means there is some configuration mismatch between the source and target projects (e.g. .NET framework version). If the DLL version works, then it means Project References are broken, in which case you can check if path provided is correct.

All system references missing Visual Studio 2013 NuGet Async

I have a solution/team project set up in visual studio 2013 and for some time have had a working NuGet Microsoft.Bcl Async Package installed for NET Framework 4.0. Today when opening the project all of the default .NET system library references cannot be found, They just have a warning symbol next to them. I have 49 warnings when building the project all saying 'The referenced component 'System.X' could not be found. Or 'The referenced component 'Microsoft.X' could not be found. Yet references to other projects in the solution remain intact.
If it is of any significance I have been using the built in version control system to keep backups of my code and access it from my other pc with the same configuration.
Looking at the other questions on stackoverflow with similar issues people seem to point towards NuGet as potentially causing the problem but without any solution that seems to work for me. I have tried the obvious solution of removing and re-adding the reference using both the file browser and the Framework tab but neither has worked so far.
I cannot currently compile the project as I get this warning, undoubtedly caused by the missing references in the first place.
Error 31 The "EnsureBindingRedirects" task could not be loaded from the assembly C:\Users...\Visual Studio 2013\Projects\AlgorithmToolsTFVC\AlgorithmToolsSuite\AlgorithmTools\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.Tasks.dll. Could not load file or assembly 'file:///C:\Users...\Visual Studio 2013\Projects\AlgorithmToolsTFVC\AlgorithmToolsSuite\AlgorithmTools\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. AlgorithmTools
A possible solution: If you are seeing yellow triangles over most of your System references, edit your .csproj file (back it up just in case), scroll to the bottom of the file, and delete these lines...
<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>
Like many others, I've been using a centralized .packages folder outside of source control. This is done by having the following lines in your NuGet.Config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="..\..\..\.packages" />
</config>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
One of the steps in achieving this, is to check your project file does not use the old NuGet.targets file anymore (the only file in your .nuget solution folder should be NuGet.Config).
When NuGet thinks it should check the NuGet.targets file, and it's not there, it will fail checks to basic references too (like System.Core, WindowsBase and PresentationCore).
Update: See this related topic/answer on how to completely do away with .nuget folders in your solution! It can be set at user-profile level in your AppData.
I was able to solve this issue by first running an update on all NuGet packages in the solution and then removing and re adding references to the libraries included or overridden by the package.
Just had the same problem.
The reason for me was that all the files inside the Nuget package, suddenly become 0 byte size. I mean DLLs, nupkg file etc.
I reinstalled the package and it worked for me.
I had exactly the same problem with my project on team foundation server. I had the error saying "EnsureBindingRedirects" task could not be loaded from the assembly C:\Users...\Visual Studio..." and many warnings saying "The referenced component 'Microsoft.X"
The solution was very easy. All I had to do was copy my entire project folder into another location and it worked.
Had a similar problem. After wasting 2.5 hours trying to find a solution, I fixed it simply by opening the project in VS 2013, enabling NuGet package restore and rebuilding. Fixed immediately and now it works in VS 2015 just fine.
Just had the same issue and solved it by executing the following command in package manager console:
Update-Package -Reinstall
If you want to do this for a specific project you can use:
Update-Package -ProjectName 'ProjectNameGoesHere' -Reinstall

Lost shared code reference in Universal Apps

Anyone know why when I reopened Visual Studio my reference to the shared project is no longer referenced and when I try to add the reference back manually I can't do it. I did not remove the shared project to begin with.
I only have SignalR as referenced if that'll make any difference.
Update
Here's the link if anyone is interested for the Visual Studio logs
I ended up creating a new Universal apps and compare the .csproj. I edited the existing .csproj and added this back. It worked but still doesn't explain why it disappeared.
<Import Project="..\UBelt.WindowsUniversal.Shared\UBelt.WindowsUniversal.Shared.projitems" Label="Shared" />

VS2012 $(exists) only accepts scalar values

Okay, this is more of a build error than a programming error. I have never had much reason to get my hands dirty with builds, so this error is baffling me.
I have tried googling this error with little results, the responses are either nonexistent, incomprehensible or not applicable.
The error is:
The "exists" function only accepts a scalar value, but its argument
"$(PackageSourceManifest)" evaluates to "[same path];[same path]" which is not a
scalar value. C:\Program Files(x86)\MSBuild\Microsoft\VisualStudio\
v10.0\Web\Microsoft.Web.Publishing.targets
Anyway, I dug into Microsoft.Web.Publishing.targets and I found the line where it is erroring out. I have verbose builds on where I was attempting to see if I could find anything that stuck out to me that I could fix.
Nothing.
I have googled how to change Package Source Manifests, I have looked in Build Properties, I have searched for a source manifest or even something that says source manifest, nothing. Maybe I am looking too hard or maybe I just don't know what to look for.
Any ideas on how to fix this and what caused this?
Open your .csproj file and look for any duplicated import tag.
In my case the .csproj had two lines like this:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio
\v10.0\WebApplications\Microsoft.WebApplication.targets" />
Remove one of them fixed the problem.
Had the same issue in VS 2012 -
Error 48 04115: The "exists" function only accepts a scalar value, but its argument "#(_UnmanagedRegistrationCache)" evaluates to "obj\TheQueueData.sqlproj.UnmanagedRegistration.cache;obj\TheQueueData.sqlproj.UnmanagedRegistration.cache" which is not a scalar value. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets 1091 7 TheQueueData
Closing and re-opening the solution did the trick for me.
I had the same issue, due to improper import of $MSBuildExtensionsPath32$. It's obvious that v10.0 is for VS2010 whereas you're on VS2012 (v11.0).
Therefore, change your import to:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" />
For other, if you have VS2013 (v12.0), you can change it to:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets" />
Note: if your remove this line like #giacomelli suggested, you'll not be able to use define your custom target file.
From MSDN : MSBuildExtensionsPath32
http://msdn.microsoft.com/en-us/library/ms164309.aspx
Introduced in the .NET Framework 4: there is no difference between the
default values of MSBuildExtensionsPath and MSBuildExtensionsPath32.
You can set the environment variable MSBUILDLEGACYEXTENSIONSPATH to a
non-null value to enable the behavior of the default value of
MSBuildExtensionsPath in earlier versions. In the .NET Framework 3.5
and earlier, the default value of MSBuildExtensionsPath points to the
path of the MSBuild subfolder under the \Program Files\ or \Program
Files (x86) folder, depending on the bitness of the current process.
For example, for a 32-bit process on a 64-bit machine, this property
points to the \Program Files (x86) folder. For a 64-bit process on a
64-bit machine, this property points to the \Program Files folder. Do
not include the final backslash on this property. This location is a
useful place to put custom target files. For example, your target
files could be installed at \Program
Files\MSBuild\MyFiles\Northwind.targets and then imported in project
files by using this XML code:
I think this happened to me when I a tried to Web Publish a project in VS2012 that had originally been a VS2010 project. So recreating the project in VS2012 is a way to cure it.
Or as #Giacomelli mentions, deleting the reference to the v10.0 targets. Note that V10.0 = VS2010 and v11.0= VS2012
I had a similar issue in VS2013. I had no duplicates. The solution that worked for me was clearing the Visual Studio cache. http://blogs.msdn.com/b/willy-peter_schaub/archive/2010/09/15/if-you-have-problems-with-tfs-or-visual-studio-flush-the-user-cache-or-not.aspx
I got the same error in VS2013, but only when I try to rebuild the project. Below how I solve the problem in my conditions, I hope that is also useful to other people.
Configuration:
I have my typescript files in separate projects in the solution.
Those projects were migrate for VS 2012.
Cause:
when I click on the error in Microsoft.Web.Publishing.targets files I discovered that the project was using the VS2012 version of those files. That is the projects where only partially migrated form VS2012 to VS2013.
Solution:
Open the typescript project (first unload project)
Search for:
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
Comment the line VSToolsPath
Save and close the file
Reload the project You can see a migration
screen from visual studio notifying you that the project was upgrade.
rebuild the project, now should work
I just had the same problem and checking my .csproj file I found nothing wrong, no duplicate imports - nothing.
After stumbling 30 minutes I got it fixed by opening my .csproj file and rearranging tags in it.
Initially I moved them all to the top, but got an error message that OutputPath is not defined, then I moved all of them right below the where they were defined and everything worked. All of them except:
Most probably moving NuGet.targets from the bottom of the file was what actually fixed it. I have no idea, nor I want to waste more time.
Hope this helps someone.

Categories