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:B8akWorkspaceB8akProjectB8akSolutionB8AK.Portalbinroslyncsc.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 binroslyncsc.exe because I did not configure anything related to Roslyn nor I intend to use Roslyn in my project.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
TL; DR
run this in the Package Manager Console:
Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
More information
This problem is not related to Visual Studio itself, so answers suggesting adding build steps to copy files over are rather a workaround. Same with adding compiler binaries manually to the project.
The Roslyn compiler comes from a NuGet package and there is/was a bug in some versions of that package (I don’t know exactly which ones). The solution is to reinstall/upgrade that package to a bug-free version. Originally before I wrote the answer back in 2015 I fixed it by installing following packages at specific versions:
- 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.
Method 2
The problem with the default VS2015 templates is that the compiler isn’t actually copied to the tfrbinroslyn 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)binroslyn" /> <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)binroslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" /> </Target>
Method 3
A clean and rebuild worked for me!
Method 4
Your build is trying to find binroslyncsc.exe
because the following packages have been added to your project. Just review your 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 the 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 on 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>
Method 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)binroslyn" />
<Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)binroslyn" 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.
Method 6
Too late for an answer but still posting incase it helps anyone.
Following the below steps fixed the error for me:
- delete packages folder
- open VS
- rebuild
- observe that NuGet packages are restored, but binroslyn isnt created
- unload project
- reload project
- rebuild
- observe that the binroslyn has been created now.
Method 7
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 “binroslyn” folder wasn’t created on build or rebuild until I reloaded the project.
Method 8
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
Method 9
0. The quick fix
As already noted in the currently highest voted answer,
the quick fix is to use the package manager, Tools > Nuget Package
Manager > Package Manager Console, to run
Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
1. Code to reproduce the error
Here is code that reproduces the error:
https://user.it.uu.se/%7Ehesc0353/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)
Consider trying the example code provided in the zip file above.
If no changes are made, Ctrl+F5 will reproduce
the error.
2. A more robust solution
An alternative solution is to remove an attribute from the project’s
Web.config
file.
(Web.config
is in the same directory as the .csproj
file.)
This will automatically and silently recreate your packages if they
are missing.
Open the Web.config
file in a text editor or in Visual Studio.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings></appSettings>
...
<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 the tag configuration > system.codedom > compilers >
compiler language=”c#;cs;csharp”, completely remove
the type
attribute.
– In short, remove the line that starts with
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider,
.
1
Visual Studio will take care of the rest.
– No more Server Error in '/' Application
.
3. HTTP Error 403
In the example provided above, hitting Ctrl+F5
will now result in an HTTP Error 403.
Try replacing http://localhost:64195
in your web browser with
http://localhost:64195/api/products
.
The web API now displays correctly:
As a provocation, I tried removing the whole package
directory from
the Visual Studio project.
It was automatically and silently recreated as soon as the project was
rebuilt.
References
1 Presumably, the same fix works for Visual Basic as well
as for C#, but I haven’t tried it.
Method 10
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 didn’t see the same error. This works as expected.
Method 11
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)
Method 12
- Clean Solution
- Rebuild Solution
,These two steps worked for me.
Method 13
For VS 2019 remove the following node completely:
<system.codedom> </system.codedom>
Method 14
You need to install Microsoft.CodeDom.Providers.DotNetCompilerPlatform.BinFix,
was especially created for that error
Method 15
In my case, before trying any of the other solutions, I switched to a “Release” configuration, rebuilt (the folder got created) and then switched back to “Debug”, while the folder remained intact.
This was a checkout from source control of an older solution and apparently the original (automatic) package restore and building the project didn’t create that folder in the bin directory.
Note that at time of writing this, the blamed component has reached v.2.
Method 16
- 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)
Method 17
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
Method 18
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)packagesMicrosoft.Net.Compilers.1.1.1tools*" /> </ItemGroup> <MakeDir Directories="$(WebProjectOutputDir)binroslyn" /> <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)binroslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" /> </Target>
Method 19
This is a known issue with Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.6. Downgrading to 1.0.5 fixed this for me.
Method 20
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 'binroslyncsc.exe' relative to 'T:workspacemachine.engineMachine.engine.Test': Invalid URI: The format of the URI could not be determined.. See the inner exception for more details. [T:workspacemachine.engineMachine.engine.TestMachine.engine.Test.csproj] MSBUILD : OctoPack error OCT-1676060969: System.Exception: Failed to build the path for 'binroslyncsc.exe' relative to 'T:workspacemachine.engineMachine.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:workspacemachine.engineMachine.engine.TestMachine.engine.Test.csproj] MSBUILD : OctoPack error OCT-1676060969: at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) [T:workspacemachine.engineMachine.engine.TestMachine.engine.Test.csproj] MSBUILD : OctoPack error OCT-1676060969: at System.Uri..ctor(String uriString) [T:workspacemachine.engineMachine.engine.TestMachine.engine.Test.csproj] MSBUILD : OctoPack error OCT-1676060969: at OctoPack.Tasks.Util.OctopusPhysicalFileSystem.GetPathRelativeTo(String fullPath, String relativeTo) in Z:buildAgentworkDir20ba9f2e0d5e4022sourceOctoPack.TasksUtilOctopusPhysicalFileSystem.cs:line 211 [T:workspacemachine.engineMachine.engine.TestMachine.engine.Test.csproj] MSBUILD : OctoPack error OCT-1676060969: --- End of inner exception stack trace --- [T:workspacemachine.engineMachine.engine.TestMachine.engine.Test.csproj] MSBUILD : OctoPack error OCT-1676060969: at OctoPack.Tasks.Util.OctopusPhysicalFileSystem.GetPathRelativeTo(String fullPath, String relativeTo) in Z:buildAgentworkDir20ba9f2e0d5e4022sourceOctoPack.TasksUtilOctopusPhysicalFileSystem.cs:line 224 [T:workspacemachine.engineMachine.engine.TestMachine.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:buildAgentworkDir20ba9f2e0d5e4022sourceOctoPack.TasksCreateOctoPackPackage.cs:line 443 [T:workspacemachine.engineMachine.engine.TestMachine.engine.Test.csproj] MSBUILD : OctoPack error OCT-1676060969: at OctoPack.Tasks.CreateOctoPackPackage.Execute() in Z:buildAgentworkDir20ba9f2e0d5e4022sourceOctoPack.TasksCreateOctoPackPackage.cs:line 190 [T:workspacemachine.engineMachine.engine.TestMachine.engine.Test.csproj] Done Building Project "T:workspacemachine.engineMachine.engine.TestMachine.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.
Method 21
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.
Method 22
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.
Method 23
Upgrading Microsoft.CodeDom.Providers.DotNetCompilerPlatform
from 1.0.0 to 1.0.1 fixed this for me.
Method 24
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)" />
Method 25
In my case by just Deleting everything inside the bin folder and recompiling did all the work for me.
Method 26
Open the project file and remove all references with Import Project=”..packagesMicrosoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0….
Open web.config and remove all system.codedom compilers attributes
Method 27
The problem with the default VS2015 templates is that the compiler isn’t actually copied to the {outdir}_PublishedWebsitestfrbinroslyn
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)binRoslyn" md "$(WebProjectOutputDir)binRoslyn" start /MIN xcopy /s /y /R "$(OutDir)roslyn*.*" "$(WebProjectOutputDir)binRoslyn" </PostBuildEvent> </PropertyGroup>
Method 28
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"
from the
version="1.0.0" targetFramework="net452" />
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
Method 29
Delete the Bin folder in your solution explorer and Build the solution again. That would solve the problem
Method 30
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:inetpubwwwrootmyAppbinroslyncsc.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
packagesMicrosoft.Net.Compilers.1.3.2tools
This solved my problem.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0