I have a solution that has been working for several years. Today I went to add a new project for the first time in months of constant development. Everything was fine and coded away. Went to build and found that it cannot find any of the project references I added.

The type or namespace name 'blah' could not be found (are you missing a using direcive or an assembly reference?)

These references are to projects in the same solution and verified they are project references in the CSPROJ file. Visual Studio has no issue finding the reference because I can code against the referenced objects just fine. It's only when I build that I have issues. Currently doing Debug with AnyCPU.

Doing Google searches, I kept finding notions that the issue could be the target framework is .NET 4 Client Profile in either my new project or references. However, this is not the case. All projects are .NET 4, not Client Profile (I verified). The even weirder thing is that these references are all working fine in the existing projects.

I can get it to build if I make the new project .NET 4.5 which makes me think that something is wrong with my target framework of .NET 4. I am currently lost and not sure what to do.

Below is the project file. I had to clear the file names and project names.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.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')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{48AED04F-6928-45F4-8C1D-A5E6713B5120}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>MyNamespace</RootNamespace>
    <AssemblyName>MyNamespace</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <TargetFrameworkProfile />
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>..\Build\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="SomeFileThatReferences.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Ref1.csproj">
      <Project>{6E0EEABF-52D7-4020-9242-AFDC33B5DAA0}</Project>
      <Name>Billing.Bills</Name>
    </ProjectReference>
    <ProjectReference Include="..\Ref2.csproj">
      <Project>{6764A403-DA4C-42FF-A89F-E1EEA7FEF0A3}</Project>
      <Name>Billing.Business</Name>
    </ProjectReference>
    <ProjectReference Include="..\Ref3.csproj">
      <Project>{9D9AB79F-D52A-4EC8-B2B7-9C605EFDBFDE}</Project>
      <Name>Billing.Reports</Name>
    </ProjectReference>
    <ProjectReference Include="..\Csla\Csla.Net4\Csla.Net4.csproj">
      <Project>{1FCE45FF-C391-4ED1-A9C4-F71CAF8773E6}</Project>
      <Name>Csla.Net4</Name>
    </ProjectReference>
    <ProjectReference Include="..\Ref4.csproj">
      <Project>{3972242B-DF6A-4B9B-9121-6138090CA114}</Project>
      <Name>Core</Name>
    </ProjectReference>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

Thanks in advance for any answers/suggestions.

有帮助吗?

解决方案

Figured it out. Apparently I was missing a reference that was unbeknownst to me. All the other projects were referencing Microsoft's BCL Portability Pack. Once I saw that in NuGet and all projects had it except the new one, I immediately referenced it and now everything builds.

That was a fun ghost hunt.

其他提示

Another reason for this annoying error. Found this by looking at the warning messages. The error messages on build did not give the needed info:

Warning 6 The primary reference "C:..path-to-you-solution-ref.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.5.1" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".

Being I'm on a clean install of VStudio, looks like the default project is not set yet to the higher version as I had it. So a version disparity (referencing a higher version from a lower one) will do this.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top