System: Windows 7 Professional 64 bit, PowerShell v 2.0, no Visual Studio (can't be installed and others too)
Trying to run PowerShell from C#. This is the code snippet:
using System;
using System.Management.Automation;
class Hello {
static void Main(string[] args) {
PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-Process");
Console.WriteLine("Process Id");
Console.WriteLine("----------------------------");
foreach (PSObject result in ps.Invoke()) {
Console.WriteLine(
"{0,-24}{1}",
result.Members["ProcessName"].Value,
result.Members["Id"].Value);
}
}
}
Error:
e:\foo.cs(2,25): error CS0234: The type or namespace name 'Automation' does not exist in the namespace 'System.Management' (are you missing an assembly reference?)
Since no Visual Studio is there, I am running code in raw manner. Because of error, I downloaded dll from http://www.dll-found.com/system.management.automation.dll_download.html and placed in dir as per instruction. After rebooting machine, there was no success.
First, I want to ask a general question. How to install missing assembly or dll file (only), because for some you might have to install whole Windows or PowerShell SDK or .NET Framework.
EDIT
I have place downloaded dll file in C:\Windows\SysWOW64, C:\Windows\system32, C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5 and C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0.
I am compiling using:
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /target:exe /out:E:\foo.exe E:\foo.cs
WARNING: Never ever download DLLs from random websites in any sane situation. Use NuGet packages (or whatever your preferred package manager is for your project) whenever possible. If a DLL is not found, there is almost always a good reason for it, and you need to find out what it is and fix it, not just get the DLL from the internet.
If you have this problem after re-targeting an old project to, for example, .NET 4.8, then it is because NuGet package names have changed.
Uninstall the package System.Management.Automation
Install the package Microsoft.PowerShell.5.1.ReferenceAssemblies (NuGet)
This package name appears in the documentation of classes in the namespace System.Management.Automation.
NuGet worked for me.
PM> Install-Package System.Management.Automation.dll -Version 10.0.10586
You must use /reference command line parameter to csc.exe, described in MSDN:
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /reference:system.management.automation.dll /target:exe /out:E:\foo.exe /E:\foo.cs
Related
I am trying to set up a new TeamCity build job and am facing a build issue.
The build failed because of missing references within ResolveProjectReferences step.
For instance :
JSonTools\JSonHelper.cs(21, 7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Prior to the build step, 2 restore nuget steps are set up and both ran successfully (one for sdk like project and the second for previous version, in this order)
When I run my solution on the agent and restore nuget packages through VS it is working fine (and TC job will run successfully if made on the same agent)
I noticed the dlls pulled during the restore nuget steps are in the path of my sln, while it seems to be require on others path.
Several VCS are set for this job and from what i can see/understand, the failing projects seem to require the dll to be in their own path under the packages folder.
\this
\is
\my
\path
Project1.csproj
packages\ (<- contains all the Dlls)
\folder1
\Project2.csproj
\Project3.csproj
\packages\ (I have the feeling some Dlls should be here but the folder doesn't exist)
\folder2
\Project4.csproj
\packages\ (same as previously)
Did I missed something ?
Any help would be appreciated.
Thanks,
Cervelle
I am new to .net/C#. I am trying to build a project but getting a lot of missing reference error.
When I am trying to install the packages like mentioned in example, I am getting error that it already exists in the project.
PM> Install-Package Microsoft.AspNet.WebApi.Core
Package 'Microsoft.AspNet.WebApi.Core.5.2.7' already exists in project 'XXXXXXystemApi'
Time Elapsed: 00:00:16.0349189
Also, as in below screenshot, I see that there are few references which have a little warning signs which might be pointing towards what is wrong with my setup.
The type or namespace name 'Http' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
I tried to Add references to the project but I am not seeing any entry for System.Web.Http under add reference dialog.
How do I fix all this ?
Try running
dotnet restore
in the Package Manager Console
Also, unloading and reloading the project has worked for me before
(Right-click on the project name in the Solution explorer to unload and reload)
Here is what finally solved my problem.
use NuGet and downgrade a version of library you are having issue with ; then re-install the right version. Accept Licenses (which is probably what was needed). Important: close and reopen visual studio.
Reference link : solution ref
So, I have a MVC 4 project in C# and I am using Visual Studio For Web 2012 Express.
I cannot compile the projecto due to the error:
The type or namespace name 'BundleCollection' could not be found (are you missing a using directive or an assembly reference?)
Normally, this would mean that a library is missing. Thus after making a quick search on the internet I used NuGet to install Microsoft.AspNet.Web.Optimization, but that still did not work.
What makes this intriguing to me is that BundleCollections should be known to the application by deafult. I can only imagine that I have added a dependency that messed everything up, but I really can't know for sure.
How can I fix this problem? What am I missing here?
Code:
using System;
using System.Web;
using System.Web.Optimization;
namespace Dockis
{
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
IItemTransform cssFixer = new CssRewriteUrlTransform();
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
//...
}
}
}
EDIT
After checking my references folder I tried running the command Install-Package System.Web.Optimization, however I cannot install this package. I get the following error:
Install-Package : One or more errors occurred.
At line:1 char:16
+ Install-Package <<<< System.Web.Optimization
+ CategoryInfo : NotSpecified: (:) [Install-Package], AggregateException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
What is odd, is the fact that running Install-Package System.Web.Optimization.Less works, and fixes some depencie problems, but not all of them. Thus I believe I really need the first command to work.
What am I doing wrong?
There is no clear answer for this question.
I managed to fix the project only by re-creating it, and then downloading all the DLLs in a different order, closing and re-opening the visual studio several times while doing it.
Aparently there was some conflict between some of the packages, but that was impossible to guess until I had re-created the project from scratch again.
Running Install-Package Microsoft.AspNet.Web.Optimization did solve the problem after the clean install however, so I recommend it.
I thank everyone for the help.
PM> Install-Package Microsoft.AspNet.Web.Optimization
Install Microsoft.AspNet.Web.Optimization on the NuGet Package Manager. If it's already installed but not working try install a previous version and then the last version again. Worked for me, :)
This is just an addition to the solutions already identified for this issue. In my case, none of the above solutions worked. In the end, I had to manually locate the DLL in my .NET folders on my local drive and add the System.Web.Optimization.dll to my project manually.
Visual Studio 2017 indicated sucessful installation of the Microsoft.AspNet.Web.Optimization.1.1.3 package, however, did not allow the DLL to be added to the project. So even though the Nuget install was successful, the app would not compile. Manually adding the DLL to the project fixed it.
For broken projects:
Right-click on References -> Manage NuGet Packages
Find Microsoft.AspNet.Web.Optimization in the browse section
Downgrade it to the previous version
If everything is ok, then roll it back to the latest version
Should work for such kind of situations.
In my case this problem was fixed by closing Visual Studio, deleting the .vs and packages folders. Then I started Visual Studio again and ran Update-Package -reinstall in the Package Manager Console and finally installed Microsoft.AspNet.Web.Optimization.
I am working on setting a project to use bamboo for CI testing, but have hit a hitch when attempting to compile unit tests. We are using the .NET framework 4.5 and NUnit v2.6.3.13283. When I am in bamboo, I have set up the specific job to check out the source code when a new commit is pushed, and then use MSBuild to build the code. Unfortunately, when it reaches this second step, it decides that it no longer understands what NUnit is.
I have the nunit.framework.dll in the same directory (bin\Debug) as the class .dll, so I'm definitely confused as to how I should go about having MSBuild work out building the NUnit tests.
Any help would be appreciated.
EDIT: Error log for those not faint of heart.
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig
/nowarn:1701,1702 /nostdlib+ /platform:AnyCPU /errorreport:prompt
/warn:4 /define:DEBUG;TRACE
/reference:c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll
/reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll
/reference:"C:\build-dir\UCL-UNL-JOB1\Unit Class
Library\bin\Debug\Unit Class Library.dll" /debug+ /debug:full
/filealign:512 /optimize-
/out:obj\Debug\UnitClassLibraryNUnitTests.dll /target:library
AngleNUnitTests.cs
"C:\Users\Bamboo\AppData\Local\Temp.NETFramework,Version=v4.5.AssemblyAttributes.cs"
AngleNUnitTests.cs(5,7): error CS0246: The type or namespace name
'NUnit' could not be found (are you missing a using directive or an
assembly reference?)
[C:\build-dir\UCL-UNL-JOB1\UnitClassLibraryNUnitTests\UnitClassLibraryNUnitTests.csproj]
AngleNUnitTests.cs(12,10): error CS0246: The type or namespace name
'Test' could not be found (are you missing a using directive or an
assembly reference?)
[C:\build-dir\UCL-UNL-JOB1\UnitClassLibraryNUnitTests\UnitClassLibraryNUnitTests.csproj]
etc.
You need to use a previous task to MSBuild one (Maybe you could consider to use the VisualStudio Task it works like a charm).
This previous task is a Command Task, it will update the Dlls related to the NuGet Package, in order to achieve it:
Create a New Executable on Bamboo, pointing to the nuget.exe file (if you don't have it you could download from https://www.nuget.org/
Create a New Command Task with the executable your created on the previous step.
On the Argument field: "restore YourSolution.sln"
In my approach I am using a VisualStudio task and after this one a MSTest Runner task.
When using Nuget with a source code repository, you have a couple of options.
1) check in your nuget executable to source code and create a bamboo command task that calls that location relative to the build directory, ${bamboo.build.working.directory}\tools\Nuget.exe.
2) Install the Nuget exe directly on the build server. Then you can create a new executable on Bamboo that you can reference in any task.
To create a new executable for use in tasks, use this - https://confluence.atlassian.com/display/BAMBOO/Defining+a+new+executable+capability
I guess you are using NuGet?
If so, you need to enable NuGet Package restore, because MSBuild does not know how to resolve these NuGet packages. This will create a .nuget directory in your solution which needs to be pushed the repository bamboo uses for the build.
Second problem I encountered when configuring the NUnit test runner with bamboo: the nunit-console.exe uses .NET Framework 3.5 which was not installed on my build server.
I am trying to run a C# console application on my server which is running Ubuntu Server 12.04. I have installed Mono JIT version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2) and additional packages like gmcs and MonoDevelop. The file that I am trying to execute is called Program.cs and when I run the command $gmcs Program.cs I get the following errors:
error CS0234: The type or namspace name 'Tasks' does not exist in the namespace 'system.Threading'. Are you missing assembly reference?
error CS0246: The type or namespace name 'MySql' could not be found. Are you missing a using directive or an assembly reference?
error CS0246: The type or namespace name 'MySqlConnection' could not be found. Are you missing a using directive or an assembly reference?
I have researched into referencing the .dll files for the above namespaces but have not been able to find an answer that is clear. Most forum links suggest that I install mono - trunk, but I want to know if I should uninstall the existing mono package and then install mono-trunk.
I am new to the Unix platform and researching every step of my way. Your help will be much appreciated.
If you are compiling from the command line, you will need to pass the referenced assemblies as a series of /r or /pkg switches, such as:
mcs /r:MySql.Data.dll Program.cs
Obviously you will need to have the required assemblies installed too.
Also note that gmcs is an (old) alias for the .net 2.0 compiler, that's why it doesn't see System.Threading.Tasks (which is a .net 4 feature). See the -sdk switch of mcs.
You should probably install monodevelop to have a user-friendly IDE to help you.