在MVC4中,如果我为解决方案中的所有项目创建一个新的构建配置,单独构建Web .csproj时,我会得到以下结果:
msbuild Company.Directory.Web.csproj /p:Configuration=Dev
[Error]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(483,
9): The OutputPath property is not set for project
‘Company.Directory.Web.csproj’. Please check to make sure that you
have specified a valid combination of Configuration and Platform for
this project. Configuration=’Dev’ Platform=’Anycpu’. You may be
seeing this message because you are trying to build a project without
a solution file,and have specified a non-default Configuration or
Platform that doesn’t exist for this project.
但是,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> <!-- ... -->
解决方法
事实证明,第一个PropertyGroup很重要。 Visual Studio插入新配置(Dev)PropertyGroup之前出于某种原因。我猜它的一个bug。我固定它通过移动新配置后的其他人。
<?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> <!-- ... -->