-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Predefined type 'System.*' is not defined or imported #6615
Comments
I also encountered this problem,I found project.MetadataReferences.Count==0,I have a lot of samples that can reproduce this problem,if you need,I can copy them to you,I do hope this problem can be fixed |
If you are experiencing problems loading projects/solutions with MSBuildWorkspace you'll want to try adding these redirects for the msbuild API to your application's .config file. These are the same redirects the msbuild.exe and devenv.exe (visual studio) use.
|
I have added these redirects,but not work,I testing project is https://github.com/opensim/opensim.git,after the download,run runprebuild.bat and load OpenSim.sln,almost all projects MetadataReferences is 0 |
I've taken a look at the opensim projects. The opensim project's are failing to build on the command line (msbuild.exe), but not inside VS. When using the msbuild API they fail silently (without exception message.) The project files (.csproj) that are generated by the pre-build tool do not have conditional nodes that handle the default case when no configuration or platform properties are set. When the are not set, the default behavior will be used. But in this case, since there is no handling of the missing properites, that means a build failure. You can assign them when you create the MsBuildWorkspace and they will be passed along to the msbuild API which is used to interpret the project files. var ws = MSBuildWorkspace.Create(
new Dictionary<string, string>() { { "Configuration", "Debug" }, { "Platform", "AnyCPU" } }); If you do this, then the MSBuildWorkspace will successfully open the projects. |
Thank you very much,my problem is solved |
I'm experiencing this problem with just a single project in my solution, while I do pass the Configuration and Platform parameters to the Do you know other things that could cause this behavior? |
Google leads here for this issue so I'll add some extra info for people I've seen this issue (0 metadata references) occur in VS 2019 16.6 when calling Roslyn APIs on a project in the Visual Studio workspace. I've seen the same issue with MSBuildWorkspace (with the platform and configuration props defined) Calling dotnet restore on the solution doesn't fix it. |
Partial repro for context. Save this as a vbproj: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>ClassLibrary4</RootNamespace>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
</ItemGroup>
</Project>
If you inspect the workspace's projects you'll notice that all the 113 .net metadata references are missing. If you try something like If you run a dotnet restore on the project, then break process execution and look again: All is fine. Other related: |
Hi,
I am trying to compile a solution using Roslyn. I have installed in my machine VS 2013 and Build Tools 2015. But I am getting a lot of CS0518 errors from Roslyn like the following one:
error CS0518: Predefined type 'System.Object' is not defined or imported
Is not only for System.Object, but also for System.String, System.Void, etc. (all kind of standard types defined in mscorlib or other standard .net libraries).
The solution I want to compile with Roslyn compiles just fine in VS 2013. Also, after installing VS 2015 those erros are not longer given by Roslyn when compiling the same solution. Of course, the solution is also compiling fine in VS 2015.
I already verified the target frameworks of all the projects in the solution and they all target 4.5 that I have installed in my machine (otherwise it shouldn't compile with VS and it does).
I am loading the solution like this:
I searched for a solution to this problem but I only found the following link. According to that link, this problem seems to be related with non-portable projects referencing portable assemblies but I am not sure if this is the case here.
http://stackoverflow.com/questions/29523473/roslyn-compilation-doesnt-resolve-mscorlib-references
Do you know how can I solve this problem without having to install VS 2015?
Thanks a lot,
Edgardo.
The text was updated successfully, but these errors were encountered: