MSBuild目标在服务器上失败,但在本地成功

时间:2013-05-03 09:27:46

标签: asp.net-mvc-4 msbuild csproj

对于我们的Web项目,我需要项目的程序集版本来修改我们的静态内容。

我已在Web项目文件中声明了一个目标,以获取程序集标识并从中检索版本号,如:

<PropertyGroup>
    <IvanhoWebVersion>
    </IvanhoWebVersion>
  </PropertyGroup>
  <Target Name="SetIvanhoWebVersion" AfterTargets="AfterBuild">
    <Message Text="-----------------">
    </Message>
    <Message Text="Entering target SetIvanhoWebVersion">
    </Message>
    <Message Text="-----------------">
    </Message>
    <GetAssemblyIdentity AssemblyFiles="$(OutputPath)$(AssemblyName).dll">
      <Output TaskParameter="Assemblies" ItemName="AssemblyIdentities" />
    </GetAssemblyIdentity>
    <CreateProperty value="%(AssemblyIdentities.Version)">
      <Output TaskParameter="Value" PropertyName="IvanhoWebVersion" />
    </CreateProperty>
    <Message Text="Assembly version = v$(IvanhoWebVersion)">
    </Message>
    <Exec Command=" &quot;$(SolutionDir)Ivanho.Lib\TranslationGenerator\TranslationGenerator.exe&quot; &quot;$(ProjectDir)Areas\UI\Static\locales\translationsrc\Translations-EN-NL-AR.xlsx&quot; &quot;$(ProjectDir)Areas\UI\Static\locales\v.$(IvanhoWebVersion)&quot;" />
  </Target>

这在本地构建时就像一个魅力,但是当我尝试将其检入我们的TFS构建服务器时,它失败并出现以下错误:

  

无法获取“bin \ Ivanho.Web.dll”的程序集名称。无法加载文件   或汇编'Ivanho.Web.dll'或其依赖项之一。系统   找不到指定的路径。

此错误在GetAssemblyIdentity调用的同一行抛出。

我无法弄清楚为什么这不适用于构建服务器,我对MSBuild很新,有人能指出我正确的方向吗?非常感谢提前!

1 个答案:

答案 0 :(得分:1)

文件不存在或者路径错误。 看看构建服务器,看看文件是否存在。您可以使用converttoabsolutepath任务确定路径,请参阅:http://msdn.microsoft.com/en-us/library/bb882668(v=vs.100).aspx。您可以输入错误语句来检查文件,例如

<Error Condition="!Exists('$(OutputPath)$(AssemblyName).dll')" Text="FileNotFound"/>