设置OutputPath时,“没有为项目设置OutputPath属性”

时间:2012-08-31 15:33:43

标签: asp.net-mvc visual-studio-2010 msbuild asp.net-mvc-4

在MVC4中,如果我为解决方案中的所有项目创建新的构建配置,那么在构建Web .csproj时我会得到以下内容:

msbuild Company.Directory.Web.csproj /p:Configuration=Dev
  

[错误]   C:\ WINDOWS \ Microsoft.NET \框架\ v4.0.30319 \ Microsoft.Common.targets(483,   9):没有为项目设置OutputPath属性   'Company.Directory.Web.csproj'。请检查以确保您   已指定Configuration和Platform的有效组合   这个项目。 Configuration ='Dev'Platform ='AnyCPU'。你可能   看到这条消息,因为你正试图建立一个没有的项目   解决方案文件,并指定了非默认配置或   该项目不存在的平台。

但是,设置了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 个答案:

答案 0 :(得分: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>
  <!-- ... -->

答案 1 :(得分:5)

尝试使用msbuild.exe从命令行构建时出现类似错误。我的问题是当我应该放'AnyCPU'时,我指的是'任何CPU'。

答案 2 :(得分: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>

然后由于某种原因还有另一个,上面显示的SHORT版本,插入到文件末尾附近。在为新PropertyGroup配置创建Release-CLOUD-STAGE元素的正确COMPLETE版本之后(并删除了两个SHORT版本) - 一切都已完成。

我不确定这是否特定于Azure,但我确实浪费了一些时间,所以我也希望分享我的发现。

答案 3 :(得分:0)

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

答案 4 :(得分: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>