使用msbuild,roslyn编译器没有被复制到AspnetCompileMerge文件夹中[英] roslyn compiler not copied to AspnetCompileMerge folder using msbuild

本文是小编为大家收集整理的关于使用msbuild,roslyn编译器没有被复制到AspnetCompileMerge文件夹中的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有一个.NET MVC项目,我正在尝试使用Jenkins部署.

我一直在让詹金斯运行msbuild,然后使用Robocopy将结果文件复制出来.我想切换到仅使用发布配置文件.使用Visual Studio在我的本地计算机上正常工作,但是在Jenkins主机上使用MSBuild失败.

它给出的错误是

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 \ Jobs \ MyProject \ Workspace \ MyProject \ myProject \ calendar.csproj]

我正在使用 microsoft.net.compilers.compilers 要吸引C#编译器,因为该项目的某些合作者仍在Visual Studio 2013上,但是我们使用了项目中的C#6语言功能.

是,在我添加发布标志之前,在詹金斯上使用msbuild构建的项目正好构建.自从添加/p:DeployOnBuild=true;PublishProfile=MyProfile设置以来,它才开始失败...然而,发布步骤从Visual Studio中可以正常运行,而Roslyn编译器甚至将复制到OBJ \ debug \ aspnetcompilemerge \ source \ source \ source \ bin \ bin \ folder上的我的本地folder上机器.什么给?

老实说,由于MSBUILD14可在Jenkins Server上使用,因此它甚至不需要Roslyn csc.exe文件.有什么方法可以使MSBuild忽略它?

我的发布个人资料

<?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>

我到目前为止尝试过的

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

手动复制编译器

我在.csproj文件中添加了步骤,以将丢失的编译器文件强制为aspnetcompilemerge目录(我已经将它们复制到bin \ roslyn目录到解决 另一个问题)

<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>

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

Based on Wesley Rathburn's answer on 一个类似的问题,我尝试制作预编译的网站,以便在发布配置文件中无法更新它:

<EnableUpdateable>False</EnableUpdateable>

尽管这揭示了我的观点中需要删除的一些死亡代码,但它在詹金斯构建过程中没有解决错误.

在本地运行MSBUILD

i can 在我的本地计算机上成功运行了MSBUILD命令.它部署到服务器和所有内容.这是我在PowerShell中运行的命令:

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

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

在我看来,也许我不需要陈述将Roslyn编译器复制到BIN文件夹,因为MSBUILD14现在可以在Jenkins上使用(我不确定是当我第一次构建项目时) .可悲的是,发生同样的错误.它正在寻找Roslyn \ csc.exe文件,即使显然需要这样做!

推荐答案

所以,我现在正在使用的解决方法(我不完全喜欢),只是为了删除 compilers 编码编译器软件包.我还必须清除.csproj和web.config文件中的引用.这也涉及从共享组件中删除这些软件包.

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

其他推荐答案

只是将其放在这里,因为我花了两天时间试图解决同样的问题(Roslyn csc.exe未复制),但是这些答案都没有解决我的问题.

事实证明, microsoft.codedom.providers.dotnetcompilerplatform 1.0.6(and 1.0.7)被损坏. 降级至1.0.5 .

我遇到的错误与这里的其他所有人相同,但是我正在使用VS 2017,而本地的网络播放和AzureDeploy都被打破了(找不到CSC.EXE).我尝试了我在互联网上找到的所有建议(大多数将其重定向回到此帖子),但是直到我降级至1.0.5.

.

所以我希望这对挣扎并刚刚升级到1.0.6的任何人都有帮助!

请参阅: https://github.com/aspnet/rosloslyncodedomprovider/issues/issues/13 https://github.com/dotnet/dotnet/roslyn/roslyn/roslyn/roslyn/sissues/21340 >

其他推荐答案

是的,我也有VS2017&VS2019和Microsoft.CodeDom.Providers.DotNetCompilerPlatform 2.0.1的问题.做了很多故障排除msbuild并深入挖掘并试图进行我自己的解决方法以及构建文件的变化,这些文件什么也没做,但这似乎根本不对.因此,我开始朝着不同的方向寻找.

我发现的是,我无法直接构建.csproj,并且在Microsoft.CodeDom.Providers.DotNetCompilerPlatform中具有nuget目标,或者由msbuild运行,或者我自己的自定义目标.

然而,与.sln一起使用msbuild .sln myproj:Rebuild的目标使一切正常.

本文地址:https://www.itbaoku.cn/post/1470802.html

问题描述

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

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.

The error it gives is

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]

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.

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?

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?

My Publish Profile

<?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.

Manually copying compiler

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>

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>

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

Running MsBuild locally

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

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.

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.

其他推荐答案

Just putting this here, because I spent two days trying to resolve this same issue (roslyn csc.exe not copied), but none of these answers solved my problem.

It turns out that Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.6 (and 1.0.7) is broken. Downgrade to 1.0.5.

I was getting the same errors as everyone else here, but I'm using VS 2017, and both local WebDeploy as well as AzureDeploy were broken (no csc.exe found). I tried all the suggestions that I could find on the internet (most of them redirect back to this SO post) but nothing worked until I downgraded to 1.0.5.

So I hope this is helpful to anyone who is struggling and has just recently upgrade to 1.0.6!

See: https://github.com/aspnet/RoslynCodeDomProvider/issues/13 and https://github.com/dotnet/roslyn/issues/21340

其他推荐答案

So yeah, I have this problem too with VS2017 & VS2019 and Microsoft.CodeDom.Providers.DotNetCompilerPlatform2.0.1 too. Did a lot of troubleshoooting msbuild and digging deep and trying to do my own workarounds and the changes in build file that just did nothing, but that didn't seem right at all. So I started looking in a different direction.

What I discovered was I couldn't build a .csproj directly and have either the nuget targets in Microsoft.CodeDom.Providers.DotNetCompilerPlatform get run by msbuild, or my own custom ones.

However using msbuild with the .sln with a target of myproj:Rebuild made everything work.