【问题标题】:The OutputPath property is not set for the C# project未为 C# 项目设置 OutputPath 属性
【发布时间】:2020-09-08 16:55:02
【问题描述】:

我在调试/重新编译 C# 项目时收到此错误消息:

没有为项目“Example.csproj”设置 OutputPath 属性。 请检查以确保您指定了有效的组合 该项目的配置和平台。配置='调试' 平台='x86'。如果有其他项目,也可能出现此错误 试图遵循对这个项目的项目到项目的引用,这个 项目已卸载或未包含在解决方案中,并且 引用项目不使用相同或等效的构建 配置或平台。

我不知道项目配置有什么问题:

<?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>      

有人有想法吗?提前致谢!

【问题讨论】:

  • 也许我错过了这里的重点,但是针对特定 CPU 平台的 C# 项目如何?通常的目标是“任何 CPU”,IIRC。
  • 我尝试更改为 AnyCPU 而不是 x86,但没有成功:(

标签: c# visual-studio project csproj


【解决方案1】:

您可以尝试三种方法:

  1. 请删除项目根目录下的bin和obj文件夹,然后重新编译程序。

  2. 请将OutputPath 放在&lt;Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /&gt; 之前。如下:

    <?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. 请检查是否引用了已卸载的项目。删除有问题的引用可以解决这个问题。

【讨论】:

  • 我尝试了这三种方法,但没有一个对我有用。在第二个中,我收到一个错误,即在 之前无法识别元素 。不过谢谢你的帮助!
  • 我对比了很多.csproj文件,发现和你的不同的是的位置。我的意思是把 放在 之后。我更新了第二种方法,你可以根据代码将 移动到合适的位置。
  • 如果您还有其他问题,请随时与我联系。
  • 再次感谢您的关注。我这样做了,现在它正在编译,当然我收到了其他错误,但是这个已经解决了!
猜你喜欢
  • 2012-08-26
  • 2014-01-20
  • 2012-02-23
  • 1970-01-01
  • 2019-10-26
  • 2018-04-29
  • 2018-06-04
  • 2014-06-10
相关资源
最近更新 更多