MSB4067:元素<Target>下方的元素<#text>未被识别。

3
从Visual Studio中,我可以成功编译代码,但是当我试图使用MSBuild编译代码时,它会抛出以下错误:
MSB4067:元素Target下面的元素#text无法识别。
请注意:我正在以发布模式构建代码,我添加的用于AfterTarget的代码仅适用于调试模式。如果我删除代码,那么它就可以正常工作。这是我的csproj文件:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" 
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B9B35177-B239-41A9-946F-3BB1CC14BD3B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ABC.MyProject.Engine</RootNamespace>
<AssemblyName>ABC.MyProject.Engine</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
 </PropertyGroup>
 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="ABCDataAccess, Version=2017.2.1.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\lib\internal\ABCDataAccess.dll</HintPath>
</Reference>
<Reference Include="ABCNotifier, Version=2016.2.2.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\lib\internal\ABCNotifier.dll</HintPath>
</Reference>
<Reference Include="ABCScheduler, Version=2016.2.2.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\lib\internal\ABCScheduler.dll</HintPath>
</Reference>
<Reference Include="log4net">
  <HintPath>..\lib\thirdparty\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="core.cs" />
<Compile Include="Model\FileInstance.cs" />
<Compile Include="Model\FileLifeCycle.cs" />
<Compile Include="Model\StateExecutor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
  <AutoGen>True</AutoGen>
  <DesignTimeSharedInput>True</DesignTimeSharedInput>
  <DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="Enterprise\Implementation\FileKarmaHandler.cs" />
<Compile Include="Enterprise\Implementation\FileKarma.cs" />
<Compile Include="Enterprise\Implementation\FileLifeCycleData.cs" />
<Compile Include="Enterprise\Interface\IFileLifeCycleData.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
  <Generator>SettingsSingleFileGenerator</Generator>
  <LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\ABC.MyProject.Core.csproj">
  <Project>{E1B4DF28-23C5-4865-B7B7-51707D2116E3}</Project>
  <Name>ABCCore</Name>
 </ProjectReference>
 </ItemGroup>
<ItemGroup>
<Content Include="Config\Archiver.xml" />
<Content Include="Config\ABClog.xml" />
<Content Include="Config\DataAccess.xml" />
<Content Include="Config\Notifier.xml" />
<Content Include="Config\Security.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
  rmdir config
  mkdir config
  rmdir sqls
  mkdir sqls
  rmdir templates
  mkdir templates
  exit 0
</PreBuildEvent>
</PropertyGroup>

<PropertyGroup>
 <PostBuildEvent>
  copy $(ProjectDir)Config\*.xml config\
  copy $(ProjectDir)..\lib\thirdparty\*.* $(ProjectDir)\bin\$(Configuration)\
  copy $(ProjectDir)..\Core\Config\*.xml config\
  copy $(ProjectDir)..\Core\sqls\*.*  sqls\
</PostBuildEvent>
</PropertyGroup>

<UsingTask TaskName="XmlPreprocess" AssemblyFile="..\lib\msbuild\lib\XmlPreprocess.MSBuildTasks.dll" />

<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Debug' ">
 
<PropertyGroup> 
 <ConfigValuesSpreadsheetFileLocation>
  ..\lib\msbuild\config\Settings.xls
</ConfigValuesSpreadsheetFileLocation>
</PropertyGroup>
<XmlPreprocess
  ToolPath="..\lib\msbuild\lib\"
  InputFiles="..\Core\Config\AlertParams.xml"
  OutputFiles="bin\Debug\config\AlertParams.xml"
  SpreadsheetFiles="$(ConfigValuesSpreadsheetFileLocation)"
  Environment="$(Configuration)"
  Clean="true"
  Validate="true" />
 
<XmlPreprocess
  ToolPath="..\lib\msbuild\lib\"
  InputFiles="..\Core\Config\CoreParams.xml"
  OutputFiles="bin\Debug\config\CoreParams.xml"
  SpreadsheetFiles="$(ConfigValuesSpreadsheetFileLocation)"
  Environment="$(Configuration)"
  Clean="true"
  Validate="true" />
 
<XmlPreprocess
  ToolPath="..\lib\msbuild\lib\"
  InputFiles="..\Core\Config\StateParams.xml"
  OutputFiles="bin\Debug\config\StateParams.xml"
  SpreadsheetFiles="$(ConfigValuesSpreadsheetFileLocation)"
  Environment="$(Configuration)"
  Clean="true"
  Validate="true" />
 
<XmlPreprocess
  ToolPath="..\lib\msbuild\lib\"
  InputFiles="Config\Archiver.xml"
  OutputFiles="bin\Debug\config\Archiver.xml"
  SpreadsheetFiles="$(ConfigValuesSpreadsheetFileLocation)"
  Environment="$(Configuration)"
  Clean="true"
  Validate="true" />
 
<XmlPreprocess
  ToolPath="..\lib\msbuild\lib\"
  InputFiles="Config\DataAccess.xml"
  OutputFiles="bin\Debug\config\DataAccess.xml"
  SpreadsheetFiles="$(ConfigValuesSpreadsheetFileLocation)"
  Environment="$(Configuration)"
  Clean="true"
  Validate="true" />
 
<XmlPreprocess
  ToolPath="..\lib\msbuild\lib\"
  InputFiles="app.config"
  OutputFiles="bin\Debug\app.config"
  SpreadsheetFiles="$(ConfigValuesSpreadsheetFileLocation)"
  Environment="$(Configuration)"
  Clean="true"
  Validate="true" />

  </Target>

</Project>

你正在使用哪个版本的MSBuild? - Martin Ullrich
它是4.0版本,不知怎么地自动开始工作了,我不知道问题出在哪里。 - M005
3个回答

4
我曾见过这种错误发生在XML格式不正确时,例如有重复的>字符。为了排除故障,您可以从csproj中删除XML节点,直到错误消失(应该在构建开始时就能看到),然后重复此步骤直到缩小到具体包含XML问题的那一行。

1

请注意来自您的源代码控制的合并/冲突标记。我刚刚遇到了一个GIT标记,导致了这个错误。


0
MSB4067:元素<#text>在元素下未被识别。
首先,您应该使用来自Visual Studio而不是.NET Framework的MSBuild。
这是因为从Visual Studio 2013开始,MSBuild 2013版本将作为Visual Studio的一部分而不是.NET Framework进行发布。有关详细信息,请查看this blog。因此,您应该使用来自以下位置的MSBuild:
C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe

其次,在发布模式下通过MSBuild构建项目时,您应该提供配置参数/P:configuration=Release,命令如下:

msbuild "YourProjectPath.csproj" /P:configuration=Release

希望这能有所帮助。

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