How to compile ZipFile class (C#) in command line - c#

Before I start describing my problem I wanna say I did everything what I supposed to do in order to make ZipFile class functional. I mean, my target framework is .Net 4.5, I added references ( System.IO.Compression.FileSystem.dll and System.IO.Compression.dll ).
I can build the project within the Visual Studio without problem, no error. BUT when I try to compile the project using Command line that's when it gets interesting. I get everytime a error "error CS0103: the name ZipFile class does not exist in the current context".
The command for compiling in the CMD is: csc /define:DEBUG /optimize /out:tbuild.exe *.cs
Does anybody come across similar or even the same problem and knows solution for it, please?

First off, +1 on the msbuild suggestion, or you could look at something like Fake
You specify the reference to System.IO.Compression.FileSystem.dll etc... in your visual studio project. Then you proceed to build your exe using only *.cs files.
I think you should specify any references other than System.dll on the command line as well like this

Related

Unable to compile C# code on Mac

I am receiving an error when I try to compile my c# source code file on my Mac. Normally I compile my source code using the mcs command on a bash terminal window and it compiles fine. But, this one particular project requires the installation of the NuGet package 'MySql.Data'. This has resulted in the following error message:
error CS0246: The type or namespace name 'MySqlConnection' could not be found. Are you missing an assembly reference?
I have tried to follow numerous solutions online to try and add the assembly reference, but my IDE just does not look like the help documentation's screenshots.
I have tried to Edit References, but no references appear. I tried to manually download the MySql.Data.dll (v.6.3.5.0) but I think it is for an outdated version of the MySql.Data class library as it does not work. Even after cleaning the code and rebuilding it.
Edit: I have also tried to add the dll that was included in the project folder but it said it could not locate the assembly (even though they are both in the same project folder).
Could not resolve this reference. Could not locate the assembly "search_feature". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. (MSB3245) (search_feature)
Edit 2: I renamed the dll file from the project bin folder to MySql.Data.dll and I no longer get the error. But it still won't compile.
The code works fine when run in Visual Studios for Mac, but I just can't compile it. Any ideas how to add the assembly reference?
I am using the most up-to-date version of Visual Studios:
Visual Studios for Mac Community 7.5.4 (build 3)
I have tried uninstalling and reinstalling Visual Studios for Mac.
My code has the library reference at the top: Using MySql.Data.MySqlclient; and the project runs. It just won't compile.

"nunit.framework.dll" could not be found

I am following the NUnit tutorial here.
My source files live in the folder C:\Users\Me\Documents\Visual Studio 2015\Projects\NUnitTest\NUnitTest. My NUnit DLL lives in the folder C:\Program Files (x86)\NUnit.org\framework\3.2.0.0\portable\nunit.framework.dll. I am certain that these paths are correct.
To compile the source file AccountTest.cs into a DLL, I ran the following commands:
cd C:\Users\Me\Documents\Visual Studio 2015\Projects\NUnitTest\NUnitTest
C:\Users\Me\Documents\Visual Studio 2015\Projects\NUnitTest\NUnitTest>csc /target:library /out:AccountTest.DLL /r:C:\Program Files (x86)\NUnit.org\framework\3.2.0.0\portable\nunit.framework.dll AccountTest.cs
However, I see these error messages:
error CS2001: Source file 'C:\Users\Me\Documents\Visual Studio 2015\Projects\N
UnitTest\NUnitTest\Files' could not be found.
error CS2001: Source file 'C:\Users\Me\Documents\Visual Studio 2015\Projects\N
UnitTest\NUnitTest\(x86)\NUnit.org\framework\3.2.0.0\portable\nunit.framework.dl
l' could not be found.
Any advice?
EDIT: I didn't forget to add a reference to NUnit inside of my solution. I also included the appropriate using statement.
It is because you did not quote the path to the NUnit assembly when you compiled from the command line. It should be this,
csc /target:library /out:AccountTest.DLL /r:"C:\Program Files (x86)\NUnit.org\framework\3.2.0.0\portable\nunit.framework.dll" AccountTest.cs
You should also know that the NUnit Console cannot run tests using the portable version of the framework at the moment. To do that, you need to create a self-executing test assembly using NUnitLite. For now, it would be easier for you to just use the .NET 4.5 version of the framework.
Is there any reason you are compiling at the command line? Visual Studio Community Edition is free and will handle compiling for you. If you are not on Windows, MonoDevelop is another good option.
Have you added a reference to your Solution?
right click Solution
hover over add
click reference
search for Nunit reference and add it
Also, make sure that you have added a using statement at the top of your project on all classes

Visual Studio saying name doesn't exist in current context

I am calling a static method on a class like
Foo.bar()
Visual studio's intellisense recognizes Foo and autocompletes bar for me (it highlights Foo and everything like it is working fine). Everything looks fine until I go to build the project, and it throws an error saying the name Foo doesn't exist in current context.
I am using this static method call in other files, so I know the class is ok. The situation is too big to post code, so I am mostly looking for reasons to start looking into that would cause intellisense to function normally but get errors on compile like this.
I've seen this error caused by differing versions of the .NET framework in the different projects. The Class Library I built was 4.5 and the application was 4.0, but the only error it gave was namespace errors. Changing the framework version on the class library and rebuilding it, then the application, resolved the error.
This can occur when namespaces, classes and variables become tangled when they have the same name. I have suffered with this before. Intellisense told me I was right, the compiler told me I was wrong! I trusted the compiler!
You have 2 options that I can think of
Search your code for Foo, and see it it is being used for something other than the static class.
Fully qualify the Foo.bar() call. MyApplication.This.That.Foo.bar();
Do it in that order...it's better to elegantly resolve the issue so you can just call Foo.bar() as this is more readable and maintainable than having MyApplication.This.That.Foo.bar(); all over the place!
In my case I was missing a } at the end of one of the methods in the middle of the code which was causing the program not see the rest of the code and complain about the Methods I have defined after that point.
Old thread I know, but I've encountered this issue when referencing a static method from within a unit test project - intellisense said the method was there, but when I tried to build/run the test (in Debug mode) I got the error 'name doesn't exist in current context'. In order to fix it I had to rebuild the project containing the referenced static method in Debug configuration (it had only previously been built in Release configuration) - after this the test built and ran OK.
I know this is a bit old topic, but I just experienced the same and for me it was because the file was not actually included in the solution.
I properly happened because I had renamed the class and then the file, which caused Visual Studio to still know the class and the namespace, but the compiler did not get the file as the renamed file was not included.
Consider doing a Clean and then a Build on the project with the problem. It is possible for the editor and Intellisense to correctly discover the class, while the compiler works with files that are out-of-date. (I had this same problem, and that's how I resolved it.)
this is an old article I know, but I just encountered this issue and has been puzzling me for couple of days, and eventually got to it: click on the class file, in Solution Explorer, then look at the Properties tab; make sure Build Action is set to "Compile".
Adjust the related file. If the error code in Default.aspx.cs, you need to change the top line in the file Default.aspx as below:
Replace "CodeFile=" with "CodeBehind"
Hope this can help.
-Thanks, Thai_FUV
I have run into this probelm a few times and so when I do, the first thing I check is if the assembly not recognized has any Nuget packages. In my cases they always have and I simply forgot to install the same packages in the assembly of which the reference to the un-recognized assembly is in. A re-build command and problem fixed. I hope this helps someone. This same error message can be given for multiple things so this particular case, may not apply. If you have not used Nuget than I would suggest trying the other answers
I also was running into this issue creating a data access layer and had static methods being called with the same symptoms: Intellisense finding it but not the compiler. I tried many of the above, including fixing the .Net version.
When adding the source files to the project I also changed the namespace.
With the file with the issue, I forgot to change the namespace to match when it was imported at another time.
Closing all tabs of MonoDevelop. Then Closing MonoDevelop. Finally opening MonoDevelop again solved the problem for me.
Mine was a little more convoluted solution. Project A referenced projects B and C: both references had Copy Local to true and both produced assemblies with identical names. When building the referencing project, the output assemblies from projects B and C were copied and one overwrote the other because they had the same name. VS was then looking for the references within the build directory and only found the assembly that had "won."
In my case I had to reload the project that was marked "missing".
Project > Unload Project
Project > Load Project
Clean, Build Solution
My solution to this problem that occurs every now and then:
Find the class that is giving you problems in the Solution Explorer and "Exclude From Project"
Rebuild that assembly (let's call it "A")
The project that used the file ("B") will ask you to "Reload" project, wait
Add the file back into assembly A, that you just removed it from, and rebuild
Now, reload project B
Then the file was found in VS and all was well.
Changing the id of the control resolved the issue for me. Apparently the id of the control existed in another part of the solution.
In my case, I was missing the following lines in my csproj file
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE</DefineConstants>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
Once I added this, I could see the variables while debugging

VS2010 C# missing project dll during build

I have problem with build in VS2010. I´m trying to develop small Prism, MVVM application.
I added new project "Toolbar" to my solution "MyApp" and during the build I get following error (propably project´s dll is not created for some reason):
Error 2 Could not load referenced assembly
"C:\net\projects\MyApp\MyApp.Modules.Toolbar\bin\Debug\MyApp.Modules.Toolbar.dll".
Caught a FileNotFoundException saying "Could not load file or assembly
'C:\net\projects\MyApp\MyApp.Modules.Toolbar\bin\Debug\MyApp.Modules.Toolbar.dll'
or one of its dependencies. The system cannot find the file
specified.".
C:\net\projects\MyApp\MyApp\ResGen MyApp
I´m quite new to VS2010 and C# so I really don´t know what happend, wheter project dll is missing because of some mistake in source code or why this can even happend? I also don´t know how to find such a mistake in source code, because VS shows up only the error mentioned above. Dependenies of the project should be ok i guess, file MyApp.Modules.Toolbar.dll really doesn´t exist in any folder on my hdd.
The problem was the bad class name defined in xaml of Toolbar project (UserControl x:Class="BAD CLASS HERE").
After many googles for a similar problem where I had at one time toyed with using open office in a .net project and then all my aspx pages had the blue squiggely line saying cli_uno couldn't be found which was referenced no where and in none of my project or lib files.
I deleted all the bin folders, a dll referencing it was hiding in one of them and making vs2010 freak out.
I realize this isn't the exact solution to the above but there isn't much out there for this error and it is a head scratcher and deleting all the bin folders worked for me so it's something to try.
You provide too litle information, so I'll ask some questions (and some possible fixes):
Is the file at the specified path to begin with?
If not, is there a project you need to build to create the dll?
If there is such project, does it build the .dll where yours is looking for it -- if not, you either need to copy it by hand or set up a post-build process to do the copy automatically after each build
If there is no such project, do you have the .dll itself somewhere. If yes, you need to copy it to the correct location.
If the .dll is at the correct location, is there some protection preventing the other project to access it?

Can't compile WebKit .NET 0.5 in VS 2010

I'm trying to compile WebKit .NET 0.5 in VS 2010 Professional but I'm getting the error:
"Could not load file or assembly
'C:\Users\Juan
Luis\Desktop\WebKit.NET-0.5-src\bin\Debug\WebKitBrowser.dll'
or one of its dependencies. The system
cannot find the file specified."
I tried removing the WebKitBrowserTest project from the solution but now I'm getting
"The type or namespace name 'WebView'
could not be found"
errors everywhere. Any idea what am I doing wrong?
replace the .dll in the projects debug folder with the original .dll's. When VS make a copy of the .dll's, it does something wrong, replacing them should fix the problem.
Try to copy '\WebKit.NET-0.5-src\bin' to your 'bin' folder.
With me, I can't build whole solution, but it runs when I select WebKitBrowserTest as StartUp project, then Ctrl + F5 (Visual Studio would ask me for rebuild JSCore, just click Yes).
If you see an error like "Retrieving the COM class factory for component with CLSID...",this link can help http://dotnetgenetics.blogspot.com/2013/06/retrieving-com-class-factory-for.html

Categories

Resources