问题
I am trying to run Asp.net MVC project retrieved from TFS source control. I have added all assembly references and I am able to build and compile successfully without any error or warning.
But I get the following error in the browser:
Could not find a part of the path \'C:\\B8akWorkspace\\B8akProject\\B8akSolution\\B8AK.Portal\\bin\\roslyn\\csc.exe\'.
Here is a full screenshot of the error page.
After few days of research, I understood that Roslyn is .Net compiler platform that offers advance compiling features. However, I do not understand why my build is trying to find \\bin\\roslyn\\csc.exe because I did not configure anything related to Roslyn nor I intend to use Roslyn in my project.
回答1:
The problem with the default VS2015 templates is that the compiler isn't actually copied to the tfr\bin\roslyn\ directory, but rather the {outdir}\roslyn\ directory
Add this code in your .csproj file:
<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>
回答2:
In my case the solution was to re-install/upgrade Nuget packages:
- Microsoft.Net.Compilers 1.1.1
- Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.1
Then I looked into .csproj and made sure that the paths to packages are correct (in my case ..\..\packages\*.*) inside tags <ImportProject>
on top and in <Target>
with name "EnsureNuGetPackageBuildImports" on the bottom. This is on MVC 5 and .NET Framework 4.5.2.
Short answer - run this in the Package Manager Console:
Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
回答3:
Your build is trying to find \bin\roslyn\csc.exe
because following packages have been added in your project.Just review you packages.config
file, you can have both of them there
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers
What is Roslyn and Who added them(packages) in project : If you’re using .net Framework 4.5.2 to create projects using VS2015, you might have noticed that the project templates use Roslyn by default. Actually Roslyn is one of open-source compilers for .NET languages from Microsoft.
Why should we delete Roslyn : If your project has Roslyn references and you are interested to deploy it no server, you will get unwanted errors on the website as many hosting providers still have not upgraded their servers and hence do not support Roslyn.To resolve this issue, you will need to remove the Roslyn compiler from the project template.
if you are not interested in using Roslyn, follow steps bellow to delete it
1. Remove Nuget packages, use the following commands from Nuget Package Console
PM> Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
PM> Uninstall-package Microsoft.Net.Compilers
2. After you do this, your web.config file should be auto-updated. In case it is not, look for the below code in web.config file and if it is found, delete this piece of code.
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"></compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"></compiler>
</compilers>
</system.codedom>
回答4:
A clean and rebuild worked for me!
回答5:
Here is a more MSBuild way of doing this.
<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>
But I notice that the roslyn files are also in my bin directory (not in a folder). The app seems to work, though.
回答6:
As noted in an issue in the Roslyn project on GitHub, a solution (that worked for me) is to simply unload and reload the project in Visual Studio.
The "bin\roslyn" folder wasn't created on build or rebuild until I reloaded the project.
回答7:
I followed these steps and it worked perfectly
- Delete all the bin and obj folders
- Clean solution and rebuild
- Run this command in powershell
Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
回答8:
After trying all of the fixes with no cigar I fixed it by updating this Nuget Package in Visual Studios:
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Mine was from 1.0.0 to 2.0.0 for reference (The error no longer shows)
回答9:

You need to install Microsoft.CodeDom.Providers.DotNetCompilerPlatform.BinFix, was especially created for that error
回答10:
- Right click on your project and select Manage Nuget Packages
- Find "Microsoft.CodeDom.Providers.DotNetCompilerPlatform"
- Simply Update to an older or newer version (doesn't matter which), and then update again back to your original version.
This re-installs all the dependencies and files of the package (like csc.exe)
回答11:
- Clean Solution
- Rebuild Solution ,These two steps worked for me.
回答12:
So, Rob Cannon's answer essentially worked for me, but I had to tweak a handful of the options. Specifically, I had to remove the condition on the target, as well as change the Include attribute, as $CscToolPath was empty when the project was being built on our build server. Curiously, $CscToolPath was NOT empty when running locally.
<Target Name="CopyRoslynFiles" AfterTargets="AfterBuild" >
<ItemGroup>
<RoslynFiles Include="$(SolutionDir)packages\Microsoft.Net.Compilers.1.1.1\tools\*" />
</ItemGroup>
<MakeDir Directories="$(WebProjectOutputDir)\bin\roslyn" />
<Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
</Target>
回答13:
This is a known issue with Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.6. Downgrading to 1.0.5 fixed this for me.
回答14:
Updating nuget packages worked for me Right click on the solution > Manage NuGet packages for solution and update all the packages and specially: Microsoft.Net.Compilers and Microsoft.CodeDom.Providers.DotNetCompilerPlatform
回答15:
In my case I just needed to go to the bin directory in Visual Studio Solution Explorer (web application project) and include the roslyn project directly. By right clicking the folder and selecting Include In Project. And check in the solution again to trigger the build process.
The roslyn folder was not included by default.
回答16:
Per a comment by Daniel Neel above :
version 1.0.3 of the Microsoft.CodeDom.Providers.DotNetCompilerPlatform Nuget package works for me, but version 1.0.6 causes the error in this question
Downgrading to 1.0.3 resolved this issue for me.
回答17:
In my case I have had issue in Jenkins when it tried to deploying it in Octopus with following error:
MSBUILD : OctoPack error OCT-1676060969: Failed to build the path for '\bin\roslyn\csc.exe' relative to 'T:\workspace\machine.engine\Machine.engine.Test': Invalid URI: The format of the URI could not be determined.. See the inner exception for more details. [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969: System.Exception: Failed to build the path for '\bin\roslyn\csc.exe' relative to 'T:\workspace\machine.engine\Machine.engine.Test': Invalid URI: The format of the URI could not be determined.. See the inner exception for more details. ---> System.UriFormatException: Invalid URI: The format of the URI could not be determined. [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969: at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969: at System.Uri..ctor(String uriString) [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969: at OctoPack.Tasks.Util.OctopusPhysicalFileSystem.GetPathRelativeTo(String fullPath, String relativeTo) in Z:\buildAgent\workDir\20ba9f2e0d5e4022\source\OctoPack.Tasks\Util\OctopusPhysicalFileSystem.cs:line 211 [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969: --- End of inner exception stack trace --- [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969: at OctoPack.Tasks.Util.OctopusPhysicalFileSystem.GetPathRelativeTo(String fullPath, String relativeTo) in Z:\buildAgent\workDir\20ba9f2e0d5e4022\source\OctoPack.Tasks\Util\OctopusPhysicalFileSystem.cs:line 224 [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969: at OctoPack.Tasks.CreateOctoPackPackage.AddFiles(XContainer nuSpec, IEnumerable`1 sourceFiles, String sourceBaseDirectory, String targetDirectory, String relativeTo) in Z:\buildAgent\workDir\20ba9f2e0d5e4022\source\OctoPack.Tasks\CreateOctoPackPackage.cs:line 443 [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
MSBUILD : OctoPack error OCT-1676060969: at OctoPack.Tasks.CreateOctoPackPackage.Execute() in Z:\buildAgent\workDir\20ba9f2e0d5e4022\source\OctoPack.Tasks\CreateOctoPackPackage.cs:line 190 [T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj]
Done Building Project "T:\workspace\machine.engine\Machine.engine.Test\Machine.engine.Test.csproj" (default targets) -- FAILED
Cause
After spending some time, I was using an internal developed component that was using Microsoft.Net.Compilers
. The reason the internal component was using Microsoft.Net.Compilers
was to overcome this issue (C#: throw invalid expression compilation) and was solved this way (How to use C# 7 with Visual Studio 2015?). This result in, when I installed the component on the main program, the Microsoft.Net.Compilers
get added it selves automatically.
Solution
My work around was, uninstall following from our internal component by (following @malikKhalil answer)
PM> Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
PM> Uninstall-package Microsoft.Net.Compilers
And chose C# 7 compiler in Jenkins instead of C# 6 and rebuild, this is to ensure everything is working and building correctly.
Than finally in my main program I tried to update my internal component. And everything than build again. It has built without any problems or issues.
回答18:
Upgrading Microsoft.CodeDom.Providers.DotNetCompilerPlatform from 1.0.0 to 1.0.1 fixed this for me.
回答19:
Open the project file and remove all references with Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0....
Open web.config and remove all system.codedom compilers attributes
回答20:
If you were adding ASPNETCOMPILER to compile your Razor views in MVC, like in this StackOverflow question, then change PhysicalPath to place where Roslyn nuget package is located (usually pointed via $CscToolPath variable):
<Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(CscToolPath)" />
回答21:
The problem with the default VS2015 templates is that the compiler isn't actually copied to the {outdir}_PublishedWebsites\tfr\bin\roslyn\
directory, but rather the {outdir}\roslyn\
directory. This is likely different from your local environment since AppHarbor
builds apps using an output directory instead of building the solution "in-place".
To fix it, add the following towards end of .csproj
file right after xml block <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">...</Target>
<PropertyGroup>
<PostBuildEvent>
if not exist "$(WebProjectOutputDir)\bin\Roslyn" md "$(WebProjectOutputDir)\bin\Roslyn"
start /MIN xcopy /s /y /R "$(OutDir)roslyn\*.*" "$(WebProjectOutputDir)\bin\Roslyn"
</PostBuildEvent>
</PropertyGroup>
Reference: https://support.appharbor.com/discussions/problems/78633-cant-build-aspnet-mvc-project-generated-from-vstudio-2015-enterprise
回答22:
I was also having same issue while running the project. here are the steps that i followed.
- Right click in solution
- select Clean solution
- After clean succeeded,Again build your project
Run the project again
This time i din't see the same error . This works as expected
回答23:
In my case by just Deleting everything inside the bin folder and recompiling did all the work for me.
Good luck to anyone having this problem.
回答24:
In my case, similar to Basim, there was a NuGet package that was telling the compiler we needed C# 6, which we didn't.
We had to remove the NuGet package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
which then removed:
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" />
from the packages.config file<system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.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.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" /> </compilers> </system.codedom>
In the system.codedom
node, you can see why it was bringing in roslyn: compilerOptions="/langversion:6
回答25:
I had the same problem when installing my application on the server when everything worked perfectly on localhost.
None of these solutions woorked, I always had the same error:
Could not find a part of the path 'C:\inetpub\wwwroot\myApp\bin\roslyn\csc.exe'
I ended up doing this:
- on my setup project, right clic, view > file system
- create a
bin/roslyn
folder - select add > files and add all files from
packages\Microsoft.Net.Compilers.1.3.2\tools
This solved my problem.
回答26:
Reboot Windows.
This is the only solution that worked for me after trying rebuild, delete contents of bin
and rebuild, restart Visual Studio.
It's yet another example of how terrible C#/.NET build tools are.
I think (after reading many of the answers), the overall conclusion is that the cause and solution of this problem heavily depends on the setup and project, so if one answer does not work, just try another. Try non-intrusive/destructive solutions, such as restarting Visual Studio, rebooting, rebuilding, etc., FIRST, before messing with NuGet packages or reinstalling development tools. Good luck!
(NOTE: Using Visual Studio 2019, and project file was originally created in Visual Studio 2015. Maybe this helps someone investigate the issue)
(EDIT: Could this be caused by not rebooting after installing/modifying the Visual Studio installation or updating Visual Studio when the installer prompts to reboot?)
回答27:
Delete the Bin folder in your solution explorer and Build the solution again. That would solve the problem
回答28:
I have webproject without csproj file and solutions mentiond here did not work for me.
Changing target .NET framework, reinstalling packages (Update-Package -reinstall
) and then building the project worked for me. You can even change target framework back after this operation(make suere you reinstall nuget packages again after).
回答29:
Other than deleting the Bin diretory from all projects inside the solution, delete the obj folders too.
In the main solution diretory remove the folder .vs
Worked for me when trying to bring an already done project into a blank solution created on git.
回答30:
First of all, here is code that reproduces the error: http://schulze.000webhostapp.com/vs/SrvrErr-reproduce.zip (Originally from https://github.com/aspnet/AspNetDocs/tree/master/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client/sample/server/ProductsApp)
Rather than using package manager (as suggested by andy250/Smoljár) to run
Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
you can remove an attribute of your project's Web.config
file.
(Web.config
is in the same directory as your .csproj
file.)
Open the Web.config
file in a text editor (or inside Visual Studio).
- In the tag configuration | system.codedom | compilers | compiler language="c#;cs;csharp"
, completely remove the type
attribute.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- ... -->
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /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.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
</configuration>
In short, remove the line that starts with type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft
.
(Presumably, the same fix works for Visual Basic as well as for Csharp, but I have not tried it.)
Visual Studio will take care of the rest. No more Server Error in '/' Application
.
In the example code I provided in the zip file above you will now get HTTP Error 403
when you hit Ctrl+F5.
Try replacing http://localhost:64195
in your web browser with http://localhost:64195/api/products
.
The web API now displays as it should:
As a provocation, I even tried removing the whole package
directory of my Visual Studio solution.
It was automatically and silently recreated as soon as I (re-)built it.
来源:https://stackoverflow.com/questions/32780315/could-not-find-a-part-of-the-path-bin-roslyn-csc-exe