Why can't I use CSharpCodeProvider? - c#

I'm trying to use Microsoft.CSharp to run C# files but I get two errors:
the errors
I'm using visual studio and unity. I used the NuGet package manager to install Microsoft.CSharp, System.CodeDom, and System.CodeDom.Compiler. I'm using all of them at the top of the file.
I don't really know anything about packages and I've never had to install one; I would just put "using packagename" at the top of my code and it worked, so I'm sorry if this is a simple fix.
I tried reinstalling all the packages and nothing changed.
I tried closing and reopening visual studio and nothing changed.
When I installed the NuGet packages it created a packages folder, app.config, and packages.config. I tried uninstalling the packages, deleting the folder and the configs, and then reinstalling the packages. It recreated the folder and configs and nothing changed.
I tried including the packages folder in the project and nothing changed.
I have other (working) packages that I didn't have to install so maybe I need to somehow install the new packages wherever those pre-existing packages are located. But idk how to do that or if it would even help.

Related

The package at 'Path' failed to uninstall

So I am using Visual Studio 2022 on Windows 11. I am trying to install a nuget package.
I get the message The package at 'Path' failed to uninstall.
So I restart and guess what - it makes no difference. Its not a re-install so the package isnt already there. It does create the folder and contents in the packages folder. I have closed VS and manually deleted it. The same package works fine in another project!
Anybody any ideas how I move this forward?
Thanks in advance.
According to your description, you can try the following methods.
Go to Tools>Options>NuGet Package Manager>General and Clear All NuGet Cache(s).
Restore package.
Reinstall package.
Check your package.config file for package dependencies.

Visual Studio still referring to packages I already uninstalled

I'm still very new to Visual Studio and C#, and I recently encountered a problem:
I migrated packages.config to PackageReference, then rolled that action back (because it didn't work with WindowsAPICodePack), reinstalled all NuGet packages with Package Manager Console, then removed all packages manually with Package Manager to start all over again, but the code
using Microsoft.WindowsAPICodePack;
still somehow refers to non-existing package. How to fix that?
References
NuGet packages installed

NuGet package refuses to uninstall in .NET Core library

I'm creating a .NET Core xUnit test project library in VS2017. I accidentally installed the System.Collections.Immutable NuGet package, and now I want to uninstall it.
First, I tried editing the csproj file and removing this line:
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" />
That didn't work, since the types from that package were still highlighted in the editor. So I tried running Uninstall-Package System.Collections.Immutable in the Package Manager Console.
The console said it couldn't find the package, so I tried putting the <PackageReference... line above back and running Uninstall-Package again. The console said the uninstall succeeded, but VS still recognized the types.
I tried closing VS, deleting .vs/, and reopening. It still recognized the types.
I tried git stashing my changes, running git clean -xdf, and running dotnet restore from the command line. Somehow, it still outputs
$ dotnet restore
Restoring packages for C:\cygwin64\home\james\Code\cs\BlockList\src\BlockList\BlockList.csproj...
Restoring packages for C:\cygwin64\home\james\Code\cs\BlockList\src\BlockList.Tests\BlockList.Tests.csproj...
...
Installing System.Collections.Immutable 1.2.0.
Installing System.Collections.Immutable 1.3.0.
...
I also tried restoring from Visual Studio instead of the command line. Still no luck.
When I searched all the files in my repo for the word Immutable, the only thing popping up is project.assets.json in the obj directory. Not a single source file contains the word Immutable. I'm confused, then, as to how it's still being referenced. How can I uninstall it?
A few other things:
I checked the 'Dependencies' drop-down for my project in Solution Explorer, and it's not listed there.
I don't want to delete my local copy of the repo and re-clone it, since I have other work stashed.
System.Collections.Immutable.dll doesn't show up at all in the bin/ directory, yet when I use one of the types in my library and run it, it works fine.
Thanks!
edit: Adding this line to the library:
System.Diagnostics.Debug.WriteLine(typeof(ImmutableArrayExtensions).GetTypeInfo().Assembly.Location);
And running it says that the assembly is located in this location:
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.1.2\System.Collections.Immutable.dll
After about an hour, I found out what the problem was. My .NET Core library referenced Microsoft.NETCore.App, which referenced System.Collections.Immutable. I looked at the dependencies for the former, but overlooked System.Collections.Immutable because that package references maybe 50 other packages. I ended up finding this out by creating a brand-new xUnit test project, and trying to see if ImmutableArray<> was present without installing anything. Sure enough, I could use it out of the box.
I had a similar issue with VS2017 and a different nuget package that wouldn't fully uninstall. I ultimately had to create a new project and cut and paste all my code into it. Kind of a sledge hammer approach, but faster than crawling through dependencies.

Nuget Packages are missing in Visual Studio

I have been using xamarin studio, it works fine when I download a sample project from mvvmcross. It compiles and deploys the device perfectly.
But when I open the project in the visual studio, there are a lot of missing packages for some reasons. Is there a way of handling ? I am using Nuget 2.8 in Visual studio 2013
When I open Nuget as follows, there is a button to restore the missing packages. I clicked on it.
Then it is attempting to download the missing packages, and then it realizes there are dependencies as follows:
Then I am attempting to download the dependency manually as follows but it shows the packages has already downloaded but I am still seeing the missing packages in the solution, nothing is affected.
Therefore I am getting hundreds of errors as follows:
When I take a look at the property of missing packages, I see as follows
You should update your NuGet Package Manager extension in Visual Studio and then try restoring the packages again.
The restore error MvvmCross.Binding already has a dependency defined for MvvmCross.Core is caused by an old version of the NuGet package manager extension not recognising the newer target frameworks that the MvvmCross.Binding NuGet package is using in its group dependencies. This bug has been fixed in a newer version of the NuGet Package Manager.
If you search for the 'already has a dependency defined' error message you will find several cases of this, such as this StackOverflow question, for example:
Can not install NuGet package
Right click on the solution in solution explorer and choose 'restore nuget packages'

Team Foundation Server won't build because nuget packages dont exist

So i created a new solution. Added all my projects to it. Downloaded all the nuget packages.
I checked it all in. On another pc I pulled the solution down. I hit build and I get a tonne of errors relating to not being able to find the dll of the packages.
So I set automatically download packages if they're missing. Still nothing works. Why is this?
When I Enabled it, it came back with an error saying that it could not modify the projects because they were locked.... This is why I want to re-enable the context menu item that allows me to enable nuget to automatically download missing packages.
I think the problem is I checked in all the packages. They all got download onto the other machine, that's why NuGet was saying that I already had the packages.
I solved this by going into the solution directory (physical path) and deleted the packages folder.
Then I built the project, and true to NuGets word it downloaded all the packages again. It also succeeded in building the application, no errors!
I would advise that if you are going to enable the NuGet package restore that you check out the solution first, once you're done check in the solution!

Categories