roslyn编译器未使用msbuild复制到AspnetCompileMerge文件夹 [英] roslyn compiler not copied to AspnetCompileMerge folder using msbuild

查看:183
本文介绍了roslyn编译器未使用msbuild复制到AspnetCompileMerge文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要使用Jenkins部署的.NET MVC项目.

I have a .NET MVC project that I'm trying to deploy using Jenkins.

我一直在让詹金斯(Jenkins)运行msbuild,然后使用RoboCopy将结果文件复制出来.我想切换为仅使用发布个人资料.发布配置文件在使用Visual Studio的本地计算机上运行正常,但在Jenkins主机上,使用msbuild失败.

I had been letting Jenkins run msbuild, then copying the resulting files out using RoboCopy. I wanted to switch to just use a publish profile. The publishing profile works fine on my local machine using Visual Studio, but on the Jenkins host it fails using msbuild.

它给出的错误是

ASPNETCOMPILER:错误ASPRUNTIME:找不到路径'C:\ Program Files(x86)\ Jenkins \ jobs \ myProject \ workspace \ myProject \ obj \ Debug \ AspnetCompileMerge \ Source \ bin \ roslyn \ csc的一部分. EXE文件'. [C:\ Program Files(x86)\ Jenkins \ jobs \ myProject \ workspace \ myProject \ calendar.csproj]

ASPNETCOMPILER : error ASPRUNTIME: Could not find a part of the path 'C:\Program Files (x86)\Jenkins\jobs\myProject\workspace\myProject\obj\Debug\AspnetCompileMerge\Source\bin\roslyn\csc.exe'. [C:\Program Files (x86)\Jenkins\jobs\myProject\workspace\myProject\calendar.csproj]

我正在使用 Microsoft.Net.Compilers nuget包之所以要引入C#编译器,是因为该项目上的某些协作者仍在Visual Studio 2013上,但是我们在该项目中使用的是C#6语言功能.

I'm using the Microsoft.Net.Compilers nuget package to pull in the C# compiler, because some of the collaborators on the project are still on Visual Studio 2013, but we're using C#6 language features in the project.

是的,在添加发布标志之前,在jenkins上使用MSBuild构建的项目就很好了.只是因为添加了/p:DeployOnBuild=true;PublishProfile=MyProfile设置,它才开始失败...但是从Visual Studio使用发布步骤仍然可以正常工作,并且roslyn编译器甚至被复制到本地的obj \ Debug \ AspnetCompileMerge \ Source \ bin \文件夹中机器.有什么作用?

Thing is, the project built just fine using MSBuild on jenkins before I added the publish flag. It's only since adding the /p:DeployOnBuild=true;PublishProfile=MyProfile setting that it started failing... yet the publish step works fine from withing Visual Studio, and the roslyn compiler even gets copied to the obj\Debug\AspnetCompileMerge\Source\bin\ folder on my local machine. What gives?

老实说,由于Jenkins服务器上提供了msbuild14,因此可能甚至不需要roslyn csc.exe文件.有没有一种方法可以使msbuild忽略它?

Honestly, since msbuild14 is available on the Jenkins server, it probably doesn't even need the roslyn csc.exe file. Is there a way I can make msbuild ignore it?

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>\\myserver\someshare\mysite</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <PrecompileBeforePublish>True</PrecompileBeforePublish>
    <EnableUpdateable>True</EnableUpdateable>
    <DebugSymbols>False</DebugSymbols>
    <WDPMergeOption>DonotMerge</WDPMergeOption>
  </PropertyGroup>
</Project>

到目前为止我尝试过的事情

我尝试更新编译器软件包.

What I've Tried So Far

I've tried updating the compiler package.

我在.csproj文件中添加了一些步骤,以将缺少的编译器文件强制复制到AspnetCompileMerge目录中(我已经将它们复制到bin \ roslyn目录中,并复制到另一个问题)

I added steps to my .csproj file to force-copy the missing compiler files to the AspnetCompileMerge directory (I'd already been copying them to the bin\roslyn directory to resolve another problem)

<Target Name="CopyRoslynFiles" AfterTargets="BeforeBuild">
  <ItemGroup>
    <RoslynFiles Include="$(SolutionDir)packages\Microsoft.Net.Compilers.1.1.1\tools\*" Exclude="$(SolutionDir)packages\Microsoft.Net.Compilers.1.1.1\tools\*.sys" />
  </ItemGroup>
  <MakeDir Directories="$(WebProjectOutputDir)\bin\roslyn" />
  <MakeDir Directories="$(WebProjectOutputDir)\obj\$(Configuration)\AspnetCompileMerge\Source\bin\roslyn" />
  <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
  <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\obj\$(Configuration)\AspnetCompileMerge\Source\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
</Target>

在发布配置文件中关闭可更新性

基于Wesley Rathburn在

Turning off Updateability in the publish profile

Based on Wesley Rathburn's answer on a similar question, I tried making the precompiled site so it could not be updated in the publish profile:

<EnableUpdateable>False</EnableUpdateable>

尽管这揭示了一些需要在我的视图中删除的无效代码,但并没有解决jenkins构建过程中的错误.

Though this revealed some dead code that needed removed in my views, it didn't fix the error during the jenkins build.

可以在本地计算机上成功运行msbuild命令.它部署到服务器和所有内容.这是我在Powershell中运行的命令:

I can successfully run the msbuild command on my local machine. It deploys to the server and everything. Here's the command I run in powershell:

&"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /p:Configuration=Debug "/p:DeployOnBuild=true;PublishProfile=MyProfile" myproject\myproject.csproj

删除完全复制编译器的语句

在我看来,也许我不再需要将roslyn编译器复制到bin文件夹的语句了,因为现在Jenkins上可以使用msbuild14了(而且我不确定那是我第一次构建项目时) .可悲的是,同样的错误发生了.它正在寻找roslyn \ csc.exe文件,即使没有明显的必要!

Removing the statements that copy the compiler entirely

It occurred to me that maybe I didn't need the statements to copy the roslyn compiler to the bin folder anymore, since msbuild14 was available on Jenkins now (and I'm not sure it was when I first built the project). Sadly, same error occurs. It's looking for the roslyn\csc.exe file, even though there's no apparent need for it to do so!

推荐答案

因此,我目前使用的解决方法(我并不完全喜欢)只是删除

So, the workaround I'm using for now (which I don't entirely like), is just to remove the dependencies on the Compilers and CodeDOM Compilers packages. I also had to clear out the references in the .csproj and web.config files. That involved removing those packages from a shared assembly as well.

这将为仍然使用Visual Studio 2013的人们打破这个项目,我不喜欢它,但是它现在建立在我的Jenkins主机上,我这样做.如果有人有更好的解决方案,我很乐意听到.

This will break the project for people still using Visual Studio 2013, which I don't like, but it builds on my Jenkins host now, which I do like. If anyone has a better solution, I'd be happy to hear it.

这篇关于roslyn编译器未使用msbuild复制到AspnetCompileMerge文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆