首页 文章

设置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' . 您可能会看到此消息,因为您正在尝试构建没有解决方案文件的项目,并且已指定了此项目不存在的非默认配置或平台 .

但是, 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>
  <!-- ... -->

Is this a bug? How can I fix it?

5 回答

  • 0

    事实证明,第一个 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

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

  • 43

    我和 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 运行良好,但新的配置没有 . 原来在项目文件中有 TWO PropertyGroup elements - 一个 - 完成 - 在项目文件的最开头:

    <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版本,插入到文件末尾附近 . 在为新的 Release-CLOUD-STAGE 配置创建了 PropertyGroup 元素的正确COMPLETE版本之后(并删除了两个SHORT版本) - 所有内容都符合 .

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

  • 5

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

  • 0

    我为Azure WebRole项目得到了相同的错误,并手动将 <PropertyGroup> 元素添加到.csproj文件中 . 但是,我不小心将它们放在几个 <Import> 语句之下 . 构建将因问题中的错误而失败 .

    Right order

    <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" />
    

    Wrong order

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

相关问题