Nuget: Deploy to IIS or Share Code - c#

This is the first time I have used NuGet and I think my question may be so basic that I can't find the answer.
Question 1)
I downloaded NuGet packages on VS2012
-Install-Package EntityFramework -Version 6.1.0
-Install-Package Microsoft.AspNet.Web.Optimization
When I create a copy of my application code, a VS2012 C# asp.net website directory and try to run it without a solution I get an error that looks like the website is not finding the Nuget packages.
If I need to share a code directory with a colleague so they can help work on it what is the process to do that?
When it comes time to deploy the code directory to IIS in production what is the process to do that? Can I simply copy the code over to the webserver as previous? Are there steps to take to ensure the Nuget packages are referenced?
Further details below:
Using VS 2012 I added the following NuGet packages to the solution:
Install-Package EntityFramework -Version 6.1.0
Install-Package Microsoft.AspNet.Web.Optimization
My target version is .NET framework 4.0 to match production.
When I move the code to another location on my computer or share it with a colleague it generates the error below.
Server Error in '/Portalv4' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'Column' could not be found (are you missing a using directive or an assembly reference?)
`Source Error:
Line 64: public DateTime FailedPasswordAnswerAttemptWindowStart { get; set; }
Line 65:
Line 66: [Column(TypeName = "ntext")]
Line 67: public string Comment { get; set; }
Line 68:
`
OK here is a weird thing- if I switch VS2012 to run the project under IIS Express the it will compile and run just fine. Any ideas as to why it does not work under Visual Studio Development server once it is separated from the solution file? There are many dll warnings about not being able to refresh under both VS Dev Server and IIS express.

Your application's ability to compile does not depend on your NuGet packages directly. The packages.config file simply remembers what was installed with NuGet so that it can manage updating and uninstalling of packages.
However, when you install a NuGet package, it will add files throughout your project. Once you install or remove a package, be sure to save your Project so that references to the package are saved. If you copy your project before saving, the package files will be in the project directory but you won't see them in the VS Solution Explorer.
Regardless of whether this is the cause of your error. You can track down the error by going to your original project, determine what assembly defines 'Column' (as described in the error) and make sure that the assembly is in the References folder of the copies project.
Good luck.

If I need to share a code directory with a colleague so they can help work on it what is the process to do that?
Start using source/version control technology, for example Git or Team Foundation Server (TFS). Both integrate nicely in Visual Studio. TFS is available for free for up to five users.
Once you're using source control, make sure to choose 'Enable Nuget Package restore' in your solution (right-click the solution in Solution Explorer). Without this option enabled, all Nuget packages will be added to your source control and you don't want that.

Related

Facing build error with System.Net.IMAP4 in Azure DevOps

I have a C# project in my local and it is working perfectly in my local machine. When I try to build the same project through Azure DevOps it gives the following build error
[error]d:\a\1\s\packages\System.Net.Imap4.0.1.0\System.Net.Imap4.sln.metaproj(0,0):
Error MSB3202: The project file
"d:\a\1\s\packages\System.Net.Imap4.0.1.0..\example\example.csproj"
was not found.
d:\a\1\s\packages\System.Net.Imap4.0.1.0\System.Net.Imap4.sln.metaproj
: error MSB3202: The project file
> "d:\a\1\s\packages\System.Net.Imap4.0.1.0..\example\example.csproj"
was not found.
[d:\a\1\s\packages\System.Net.Imap4.0.1.0\System.Net.Imap4.sln]
Project
"d:\a\1\s\packages\System.Net.Imap4.0.1.0\System.Net.Imap4.sln" (1) is
building
"d:\a\1\s\packages\System.Net.Imap4.0.1.0\System.Net.Imap4.csproj"
In the IMAP4 library, it specifically says that the following file was not found. When I added the package through Nuget Package Manager it installed perfectly but does not download the mentioned file example/example.csproj in the packages/System.Net.Imap4.0.1.0 folder.
d:\a\1\s\packages\System.Net.Imap4.0.1.0\System.Net.Imap4.sln.metaproj : error MSB3202: The project file "d:\a\1\s\packages\System.Net.Imap4.0.1.0..\example\example.csproj" was not found.
System.Net.Imap4.0.1.0 package structure
System.Net.Imap4.0.1.0/lib/net35 (inside the lib there are no files and it contains only net35 folder)
System.Net.Imap4.0.1.0/properties
What I am missing here to build the project successfully?
Note: I tried to view the hidden files also but the example.csproj file was not found.
Facing build error with System.Net.IMAP4 in Azure DevOps
This issue should comes from that nuget package. I have download that nuget package from nuget.org, then I unzip it, I found that the package did not contain the file example.csproj:
So, this issue related to the package, I am not sure if you are the Owners/Authors of that package, if yes, you need to re-create that package.
In addition, I have a long time to use/support nuget. According to my experience, this package is not correct. As we know, nuget:
An essential tool for any modern development platform is a mechanism
through which developers can create, share, and consume useful code.
Often such code is bundled into "packages" that contain compiled
code (as DLLs) along with other content needed in the projects that
consume these packages.
But that package packaged the entire project, which is not the correct way, it should only include the dll files.
You can check this document for some details.
Hope this helps.
The build error resolved with the following changes.
Navigate to this folder path /../System.Net.Imap4.0.1.0
Open the System.Net.Imap4.sln file and remove or comment the example/example.csproj line from the file.
Build the project
Build is successful

How to package and deploy a NuGet package with symbols and source code so that debugger can use THAT source code?

I have created a very simple NuGet package from a .net framework visual studio Class Library project, where the class library source is in C#.
I used this command to create the nuget package:
nuget pack MyProject.csproj -symbols -Properties "Configuration=Debug" -suffix debug
Which creates, as I expect, two nuget package file, namely:
MyProject.1.0.0-debug.symbols.nupkg
MyProject.1.0.0-debug.nupkg
These packages are basically identical other than that the one with "symbols" includes the pdb files in the lib hierarchy and source files in the src folder.
Given the duplication, I rename the file MyProject.1.0.0-debug.symbols.nupkg as MyProject.1.0.0-debug.nupkg, which overwrites one of the files, no big deal there. I now have a conventionally named package with PDB and source files in it.
I deploy this to an internal file share feed with:
nuget add MyProject.1.0.0-debug.nupkg \\InternalShare\FeedFolder
In an entirely different project, and a different solution, I now consume that NuGet package in Visual Studio with the NuGet Package Manager. All works great. And the code works fine too, in my case I made a simple console app that uses a couple of classes in the package and I have demonstrated that it uses them correctly and without incident.
So far so good.
Now I set a breakpoint in the consuming code, and attempt to step into the source to debug the package. It seems to work OK, but actually, it isn't going into the source that was distributed with the package. It actually steps into the ORIGINAL source from the creation of the package, in a completely different and unrelated folder hierarchy on my machine.
OK. So now I recreate my simple console app on a separate computer that does not have the ORIGINAL source. And on that separate computer, which is on the internal network and hence has access to the file share, I consume the NuGet package and again, everything compiles and works fine.
When I try to step into the package source code in the visual studio debugger, however, it simply doesn't work. The debugger can't find the source code even though it is right there in the package folder. (The debugger offers to disassemble the code -- not so helpful).
This seems like it should be a common use case and desire for including symbols and source code in a nuget package, so I must be doing something silly such that the debugger can't find the source.
Various versions of things:
Visual Studio: Professional 2017 15.9.11
NuGet Package Manager installed in VS: 4.6.0
CLI NuGet version: 4.8.1.5435
Targetted .NET Framework for my sample code: 4.6.1
What is my mistake?
Many thanks in advance.
================== ADDED INFO 4/17/2019, 3:30pm Pacific =======================
This isn't quite as bad as I thought. When I try to go into the code and says it can't find it, I am given the opportunity to browse to the code, so I can browse to the package (assuming I know where it is!) and set the debugger loose and everything works fine. The nice thing is that Visual Studio seems to remember where I browsed to and knows to look there next time. Not sure of that mechanism.
AND.... If I go to my original computer (with the actual package source on it) if I change that initial source, like I am getting ready for the next package, the debugger (of course) realizes that the source has changed, and likewise prompts me to look for the proper source elsewhere.
Still, it would be great not to have to jump through hoops like that, so I would still appreciate any further insights.
Back in Feb'2019 it was working. Few things which are not mentioned here and I added to csproj file are
<DebugSymbols>true</DebugSymbols>
<EmbedAllSources>true</EmbedAllSources>
<DebugType>portable</DebugType>
I packaged with nuget and command used is:
nuget pack mynuget.nuspec -Symbols -SymbolPackageFormat snupkg
I was using VS 15.9.4 and nuget 4.9.3 at that time With this I could successfully debug nuget from network path . Not sure what changed in recent releases, its not working now.
Some fundamentals:
the debugger needs PDBs to enable debugging
a symbol package should contain PDBs (it is not merely a package with a different extension)
this symbol package should be published to a symbol repository that Visual Studio debugger can request symbols from
Next:
See this doc for creating and publishing symbols package to nuget.org (.snupkg)
Then, see this doc for configuring visual studio to for using NuGet.org as a symbol source (use this value when adding a symbol server https://symbols.nuget.org/download/symbols)

The type or namespace name 'TwilioRestClient' could not be found

This is what I did:
went to
https://www.twilio.com/docs/authy/tutorials/account-verification-csharp-mvc
downloaded the code and built the code using VS2017 community edition.
I get the following error in IdentityConfig.cs
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'TwilioRestClient' could not be found (are you missing a using directive or an assembly reference?) AccountVerification.Web C:\Users\admin\Downloads\account-verification-csharp-master\account-verification-csharp-master\AccountVerification.Web\App_Start\IdentityConfig.cs 21 Active
What is the problem?
I changed nothing. Just downloaded and built the code. Shouldn't you guys give a working copy of the code?
I've managed to get this working by following these steps:
Close the solution in Visual Studio if you have it opened.
Ensure you have a nuget CLI in your path. So you can run a restore from a command prompt. This is pretty straightforward. Instructions here.
Open a command prompt at the solution directory. (C:\Users\admin\Downloads\account-verification-csharp-master\account-verification-csharp-master for you.)
Run a nuget restore. nuget restore and wait for it to finish.
You should get all the packages downloaded at the packages directory under your solution folder.
UPDATE - Looking at the code it appears that there's a mix of features from the latest version 5.x and the now deprecated version 4.x, and that's causing compilation errors. Details here.
Follow the below steps to downgrade the version to 4.7.2:
Open the solution file now.
Right-click the web project and select Manage Nuget Packages.
Search for Twilio and downgrade the version from 5.x to 4.7.2.
a) Or from the Package Manager Console Install-Package Twilio -Version 4.7.2
Solution should build successfully now.
Please bear in mind that you must setup the parameters in Local.config file before the app can work. It'll run though, but you'll not be able to go through it until the parameters are properly set.
Note: The solution contains a file named Local.config.example. When you open the solution you'll notice that Local.config file is missing.
Renaming the existing Local.config.example file to Local.config solves that issue. I had to copy the Local.config file to the test project too. This doesn't prevent the solution from building, though.
Hope this helps!

Type or namespace name 'MySQL' could not be found VS2017

Currently trying to create a connection to a MySql Database. When I added
using MySql.Data;
using MySql.Data.MySqlClient;
to my class I recieved the typical "The type or namespace name ... could not be found". A little searching made me realize I was missing the MySql.Data.dll.
I used Packet Manager console to install MySql.Data:
PM> Install-Package MySql.Data
I verified that it was installed via Tools > NuGet Package Manager > Manage NuGet Packages for Solutions, but I was still getting the build error.
At this point I figured, since the PM downloaded the .dll I'll just manually reference it via References > Add Reference > Browse > Select MySql.Data.dll.
Great!! The red squiggly went away on my using and intellisense started working for classes inside the MySql.Data namespace:
Fast forward 10 mins, I finish writing my test class and hit Build and error comes back:
So in summary, using PM to install MySql.Data got me no where. Manually adding the reference of MySql.Data.dll got my intellisense to recognize the namespace and classes, but when it comes to building I still get the error.
Pretty stumped. Anyone seen this?
Solved this issue! Turns out the newest MySql.Data.dll is built off of .Net Framework 4.5.2, while my project was using .Net Framework 3.5 Client Profile.
Changing my project's framework to 4.5.2 solved the issue. It's quite strange that VS doesn't give a better error message.
To change your project's framework right click on your project (not the solution), select Properties -> Application -> Target framework. The target framework is a dropdown on that page.
I came to this realization thanks to another stackoverflower question: Namespace not recognized (even though it is there)
In terminal after navigating to your project directory, run the following commands
dotnet add package MySql.Data -v 8.0
In this situation MySQL dll files very new. You can download older dll files and includ in your project. I prefer this version. It works for me MySql.Data.DLL
Downloaded the .dll You'll just manually reference it via References > Add Reference > Browse > Select MySql.Data.dll
I changed the reference of MySql.Data from a previous version to the current one and the error was gone. You can select that by clicking on add reference and then on the left side find recent if you have used it, change it to a current version, in my case it was from 8.0.23.0 to 8.0.25.0
I too had the similar issue. I had 3 projects -namely , Data Access Layer, Business LogicLayer and WebApplication. I went to "WebApplication" project property/Application and change the .Net Framework from 4.6.1 to 4.6
Then again it complained saying, the referenced project has higher framework version, so again i right click on the Business LogicLayer and DataAccessLayer and change the .Net Framework to 4.6 instead of 4.6.1. Now the build is successful without any noise ( no warning/no error).
I am able to successfully publish the source code as well. But still the page is not coming up, the error message in the browser is as below :
Server Error in '/' Application. The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make
sure that it is spelled correctly.
Requested URL: /
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.8.4075.0
But I think this is separate error. Now i am trying to fix this error.

Microsoft.Threading.Tasks not found

I have made a dll that wraps around some Google operations. With my first test drive it worked perfectly, but now in a real program, I get a weird assembly reference problem:
FileNotFoundException was unhandled
Could not load file or assembly 'Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Det går inte att hitta filen.
I have heard of System.Threading.Tasks (and am "using" it), but where does Microsoft.Threading.Tasks come in? The exception occurs at the last row of the snippet below.
Google.Apis.Admin.Directory.directory_v1.Data.Groups allGroupsResp = null;
var req = DirectoryService.Groups.List();
req.Domain = _settings.Domain;
allGroupsResp = req.Execute();
And there is no Microsoft.Threading.Tasks in the assembly list.
This is what worked for me:
Open the NuGet console via the Tools menu > NuGet Package Manager > Package Manager Console
From the console type in: update-package Microsoft.Bcl.Async -reinstall
After that, you may be prompted to re-start Visual Studio to finish uninstalling the package. Once you re-start, the package should be re-installed and everything should work.
Sounds like you're using the Google API .Net Client. I suggest using Nuget to install the assemblies as described on the linked page. However, if you download the source, the Microsoft.Threading.Task assmeblies are included and so it seems the code your calling is trying to access those assemblies.
You could manually move that assembly into your directory but I'd usually opt for the Nuget method unless you need to be using a particular build.
I expect you are using the "google-api-dotnet-client". Microsoft.Threading.Tasks is a dll used by this client according to google code:
https://code.google.com/p/google-api-dotnet-client/source/browse/ThirdParty/Microsoft.Threading.Tasks.dll
You probably just have to move this file into your bin directory.
Just install Microsoft.Bcl.Async nuget package!
(if you are using Google.Apis.Oauth2.v2 with UWP app)
There could be several problems - the first one you project where you've referenced this dll is not targeted to .Net4 or you just have not installed .Net4 framework on your box.
I had a similar problem with Microsoft.Threading.Tasks.PDB not being found.
Found the solution here: Cannot find .cs files for debugging .NET source code
TL;DR: VS was trying to debug the .NET framework and I was missing the debug files. But I did not actually need to debug the .NET so i did:
Tools -> Options -> Debugging -> General -> Enable just my Code

Categories