Search code examples
c#visual-studioprojectcsproj

The OutputPath property is not set for the C# project


I got this error message while debug/recompiling a C# Project:

The OutputPath property is not set for project 'Example.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='x86'. This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Configuration or Platform.

I don't know what could be wrong in project configurations:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <PropertyGroup>
    <ProjectType>local</ProjectType>
    <ProjectVersion>7.10.377</ProjectVersion>
    <OutputPath>bin\x86\</OutputPath>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{E34FF2B3-527D-4006-B312-3D88C491ADBC}</ProjectGuid>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <AssemblyName>Example</AssemblyName>
    <OutputType>WinExe</OutputType>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <PlatformTarget>x86</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\x86\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <PlatformTarget>x86</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\x86\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>      

Someone have an idea? Thanks in advance!


Solution

  • There are three methods you can try:

    1. Please delete the bin and obj folders in the project root directory then rebuild the program.

    2. Please place OutputPath before <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />. As follows:

      <?xml version="1.0" encoding="utf-8"?>
      <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
      <PropertyGroup> 
      ......
      </PropertyGroup>  
      <PropertyGroup> 
      ......
      </PropertyGroup>
      <PropertyGroup> 
      ...
      </PropertyGroup>                                       
      <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
      <ItemGroup>
      ......
      </ItemGroup>
      </Project>
      
    3. Please check whether an uninstalled project is referenced. Deleting the offending reference can solve this problem.