【问题标题】:"The OutputPath property is not set for project" when OutputPath is set设置 OutputPath 时,“未为项目设置 OutputPath 属性”
【发布时间】:2012-08-26 10:58:52
【问题描述】:

在 MVC4 中,如果我为解决方案中的所有项目创建新的构建配置,我会在单独构建 web .csproj 时得到以下信息:

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

[错误] C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(483, 9): 没有为项目设置 OutputPath 属性 'Company.Directory.Web.csproj'。请检查以确保您 已指定配置和平台的有效组合 这个项目。配置='开发'平台='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>
  <!-- ... -->

这是一个错误吗?我该如何解决?

【问题讨论】:

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


    【解决方案1】:

    我在 Azure WebRole 项目中遇到了同样的错误,并将 &lt;PropertyGroup&gt; 元素手动添加到 .csproj 文件中。但是,我不小心把它们放在了几个&lt;Import&gt; 语句下面。构建将因问题中的错误而失败。

    正确的顺序

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        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 元素 - 一个 - COMPLETE - 在项目文件的最开头:

        <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 的,但我确实在这方面浪费了一些时间,所以我也想分享我的发现。

        【讨论】:

          【解决方案4】:

          我在尝试使用 msbuild.exe 从命令行构建时遇到了类似的错误。我的问题是当我应该放置“AnyCPU”时,我指定了“Any CPU”。

          【讨论】:

            【解决方案5】:

            事实证明,第一个PropertyGroup 很重要。 Visual Studio 出于某种原因在其之前插入了新配置(开发)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 3 小时尝试 duff 解决方案,结果一炮而红,干杯!保罗
            • 嗯!!...这节省了很多挫折和时间..谢谢
            • 完美 - 立即解决了我的问题!
            • Deffo 尝试使用 \p:Platform="AnyCPU" 而不是 \p:Platform="Any CPU"。这对我有用!看这个很久了!
            • \p:Platform="AnyCPU" 太棒了。
            猜你喜欢
            • 2014-01-20
            • 2012-02-23
            • 1970-01-01
            • 1970-01-01
            • 2019-10-26
            • 2018-04-29
            • 2014-06-10
            • 2018-06-04
            相关资源
            最近更新 更多