首页 > 解决方案 > TFS 构建服务器 2015 - 转换 web.config 不正确

问题描述

我对 TFS 2015 构建服务器上的“visual studio build”任务有疑问。当我在构建服务器上构建我的项目时,它不会将转换后的 web.config 发布到正确的文件夹。我有两个 web.configs --> web(base).Debug.config 和 web(base).Release.config。

在以下文件夹中,我希望转换后的 web.config::...\TFS2015BuildAgent\work{tasknummer}\a_PublishedWebsites{backend solution}\web.config 但是转换后的 web.config 位于以下文件夹中:...\TFS2015BuildAgent \work{tasknummer}\a_PublishedWebsites\web.config

solution.csproj -文件有以下几行:

...
...
  <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>  
    <PlatformTarget>AnyCPU</PlatformTarget>
    <Prefer32Bit>false</Prefer32Bit>
  </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>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
...
...
...

  <Target Name="PostTransformAppConfig" AfterTargets="Build">
    <CallTarget Targets="TransformWebConfig" />
    <Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\webbase.config')" SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\webbase.config" DestinationFiles="Web.config" />
    <Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\webbase.config')" SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\webbase.config" DestinationFiles="$(OutDir)\Web.config" />
    <Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\webbase.config')" SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\webbase.config" DestinationFiles="$(OutDir)\_PublishedWebsites\$(AssemblyName)\Web.config" />
  </Target>
...
...
...

  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" Condition="false" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
  <PropertyGroup>
    <PreBuildEvent>attrib -R "$(ProjectDir)Web.config"</PreBuildEvent>
  </PropertyGroup>

在 TFS 服务器上的 Visual Studio Build 任务规范下方:

当我在 VS 2017 中构建我的项目(本地)时,web.config 已正确转换。此外,在本地发布时,web.config 会根据 de Debug 或 Release 配置正确转换。

但是,我已经为这个 TFS 服务器上的其他项目创建了多个构建定义,包括转换 web.config。在所有其他项目中,web.config 文件已正确/按预期转换......

所以我可能遗漏了一些东西....但是什么?

标签: c#tfsvisual-studio-2017tfsbuildweb.config-transform

解决方案


经过几个小时的搜索,问题是 $(AssemblyName) 定义错误,因此配置文件被复制到了错误的文件夹中。

本地构建/发布可能没有问题,但是当 AssemblyName 不正确时,构建服务器上会出错。


推荐阅读