当设置了OutputPath时,项目的OutputPath属性未设置

28
在MVC4中,如果我为解决方案中的所有项目创建一个新的构建配置,则当仅构建Web .csproj时会出现以下情况:
msbuild Company.Directory.Web.csproj /p:Configuration=Dev
[错误] C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Microsoft.Common.targets(483,9):项目“Company.Directory.Web.csproj”未设置OutputPath属性。 请检查以确保您为此项目指定了有效的Configuration和Platform组合。 Configuration ='Dev' Platform ='AnyCPU'。 您可能会看到此消息,因为您正在尝试构建一个没有解决方案文件并且已指定不存在于此项目中的非默认Configuration或Platform的项目。

然而,OutputPath属性已设置!

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Dev|AnyCPU'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
    <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
    <DeployIisAppPath>Port 80/directory/dev</DeployIisAppPath>
  </PropertyGroup>
  <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>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{285FBF79-7933-4AF9-AAAF-25EE7734AAAA}</ProjectGuid>
    <ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Company.Directory.Web</RootNamespace>
    <AssemblyName>Company.Directory.Web</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <MvcBuildViews>false</MvcBuildViews>
    <UseIISExpress>true</UseIISExpress>
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
    <RestorePackages>true</RestorePackages>
  </PropertyGroup>
  <!-- ... -->

这是一个错误吗?我该如何修复它?

5个回答

43

事实证明,第一个PropertyGroup非常重要。由于某种原因,Visual Studio在其前面插入了新配置(Dev)的PropertyGroup。我猜测这是一个错误。我通过将新的配置移动到其他配置后面来解决了这个问题。

<?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>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{285FBF79-7933-4AF9-AAAF-25EE7734AAAA}</ProjectGuid>
    <ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Company.Directory.Web</RootNamespace>
    <AssemblyName>Company.Directory.Web</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <MvcBuildViews>false</MvcBuildViews>
    <UseIISExpress>true</UseIISExpress>
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
    <RestorePacCompanyes>true</RestorePacCompanyes>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Dev|AnyCPU'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
    <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
    <DeployIisAppPath>Port 80/directory/dev</DeployIisAppPath>
  </PropertyGroup>
  <!-- ... -->

2
尝试了三个小时的错误解决方案,但这一个正中要害,谢谢!Paul - Paul Brown
哇!这节省了我很多的挫败和时间..谢谢 - surya
完美 - 立即解决了我的问题! - tbehunin
2
一定要尝试使用\p:Platform="AnyCPU"而不是\p:Platform="Any CPU"。这对我有用!我看了很久! - Lee Englestone
\p:Platform="AnyCPU" 真是太棒了。 - cli

6

当我试图使用msbuild.exe从命令行构建时,遇到了类似的错误。我的问题是我在应该写'AnyCPU'的地方写成了 'Any CPU'。


2
我曾经遇到过与Azure项目类似的问题。在我将新的配置Release-CLOUD-STAGE添加到解决方案后,我开始收到相同的错误信息:

项目的OutputPath属性未设置

在我打开编辑器中的ccproj文件并搜索新的配置之后,在其末尾我看到了这个内容:
  <PropertyGroup Condition=" '$(Configuration)' == 'Release-CLOUD' ">
    <OutputPath>bin\Release-CLOUD\</OutputPath>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Release-CLOUD-STAGE' ">
    <OutputPath>bin\Release-CLOUD-STAGE\</OutputPath>
  </PropertyGroup>

我觉得一切都很正常——现有的配置Release-CLOUD运行良好,但新的配置无法正常工作。原来在项目文件中有两个PropertyGroup元素,其中一个完整的位于项目文件的开头:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release-CLOUD|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release-CLOUD\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>

然后出现了另一个版本,就是我之前展示的简短版本,它插入在文件末尾附近。当我为新的Release-CLOUD-STAGE配置创建适当的完整版本PropertyGroup元素(并删除两个简短版本)后,一切都编译成功了。

我不确定这是否与Azure有关,但我浪费了一些时间,所以我想分享我的发现。


0

我在Azure WebRole项目中遇到了相同的错误,并手动将<PropertyGroup>元素添加到.csproj文件中。但是,我不小心放置它们在几个<Import>语句下面。这种情况下编译会失败并报错,就像问题描述中的那样。

正确的顺序

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Dev|AnyCPU'">
   <DebugSymbols>true</DebugSymbols>
   <OutputPath>bin\</OutputPath>
   <DefineConstants>DEBUG;TRACE</DefineConstants>
   <DebugType>full</DebugType>
   <PlatformTarget>AnyCPU</PlatformTarget>
   <ErrorReport>prompt</ErrorReport>
   <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

错误的顺序

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Dev|AnyCPU'">
   <DebugSymbols>true</DebugSymbols>
   <OutputPath>bin\</OutputPath>
   <DefineConstants>DEBUG;TRACE</DefineConstants>
   <DebugType>full</DebugType>
   <PlatformTarget>AnyCPU</PlatformTarget>
   <ErrorReport>prompt</ErrorReport
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

0

我有两个没有条件的PropertyGroup元素,我认为后者阻止了前者生效。我将所有子项合并到第一个PropertyGroup元素中,并且删除了第二个元素,之后事情开始正常工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接