【问题标题】:VSTS Build fails/Publish fails to find roslyn\csc.exe in the bin folderVSTS 构建失败/发布无法在 bin 文件夹中找到 roslyn\csc.exe
【发布时间】:2019-02-04 17:35:58
【问题描述】:

我们有一个安装了以下 nuget 包的网站项目

Microsoft.CodeDom.Providers.DotNetCompilerPlatform - 1.0.8

Microsoft.Net.Compilers - 2.4.0

web.config 有以下内容

<system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>

构建在本地运行良好。当安装DotNetCompilerPlatform 时,install.ps1 脚本会在 bin 中创建 Roslyn 文件夹,并将 csc.exe 等复制到该文件夹​​中。

代码由第三方编写并提交给我们的 VSTS 存储库。我想通过我们的测试/阶段和生产环境使用 VSTS 来构建和部署网站。

VSTS 构建管道获取源,然后恢复包并在解决方案上运行 Visual Studio 构建任务。这是一个网站项目,因此不是该网站的项目。构建失败并出现以下错误

ASPNETCOMPILER(0,0): 错误 ASPRUNTIME: 找不到一部分 路径“xxxxxxxxxx\bin\roslyn\csc.exe”。

由于构建只是对包进行还原,因此 Roslyn 二进制文件不会复制到 bin

我还尝试从项目中删除包并从web.config 中删除编译器,但随后出现错误。

错误 CS1056:意外字符“$”

我正在使用一些较新的语言功能。

我真的很想自动化预编译和发布,因为目前有太多手动步骤容易出错或滥用。

我的一个想法是在包还原后在构建管道中添加一个步骤,以从DotNetCompilerPlatform 包文件夹运行 install.ps1,这有望将编译器工具复制到 bin .即模仿安装软件包时所做的事情。但在我走这条路之前,我想看看是否有更好的解决方案。

【问题讨论】:

  • 为了我们调查这个问题,您能否将 system.debug 设置为 true 并将新构建排队,然后在此处分享调试日志?
  • 您找到解决方案了吗?我们在 azure devops 上构建的网站项目也遇到了同样的问题。

标签: c# build web azure-devops roslyn


【解决方案1】:

一个建议是更新您的 '.csproj' 以将您的构建定义(在代码本身中)更改为 copy the roslyn 直接进入 bin 文件夹而不是比default output directory

<Target Name="CopyRoslynFiles" AfterTargets="AfterBuild" Condition="!$(Disable_CopyWebApplication) And '$(OutDir)' != '$(OutputPath)'">
    <ItemGroup>
      <RoslynFiles Include="$(CscToolPath)\*" />
    </ItemGroup>
    <MakeDir Directories="$(WebProjectOutputDir)\bin\roslyn" />
    <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
</Target>

Refer this SO

这样你就不能改变 VSTS 构建定义

【讨论】:

  • 该解决方案包含一个网站项目而不是一个 Web 应用程序项目,因此不包含可编辑的 csproj 文件。
猜你喜欢
  • 1970-01-01
  • 2020-01-28
  • 2018-01-12
  • 2017-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-22
  • 2018-10-18
相关资源
最近更新 更多