我们有一个网站项目,其中安装了以下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=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
在本地构建良好的工作。安装DotNetCompilerPlatform
时,install.ps1脚本会在bin中创建Roslyn文件夹,并将csc.exe等复制到该文件夹中。
该代码由第三方编写并致力于我们的VSTS回购。我想使用VSTS通过我们的测试/阶段和prod环境构建和部署网站。
VSTS构建管道抓取源,然后还原包并在解决方案上运行Visual Studio Build任务。这是一个网站项目,所以这不是网站的项目。构建失败,出现以下错误
ASPNETCOMPILER(0,0):错误ASPRUNTIME:找不到路径'xxxxxxxxxx \ bin \ roslyn \ csc.exe'的一部分。
由于构建只是对包进行恢复,因此Roslyn二进制文件不会复制到bin中。
我也尝试从项目中删除包并从web.config
删除编译器,但然后得到错误。
错误CS1056:意外字符'$'
我在哪里使用一些较新的语言功能。
我真的想自动执行PreCompile和Publish,因为目前有太多手动步骤可能会出错或滥用。
我有一个想法是在包恢复之后在构建管道中添加一个步骤来运行DotNetCompilerPlatform
包文件夹中的install.ps1,这有望将编译器工具复制到bin。即模仿安装软件包时所执行的操作。但在我走这条路之前,我想看看是否有更好的解决方案。
一个建议是更新你的'.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>
这样您就无法更改VSTS Build定义