Updating Files in Existing Nuget Package - asp.net

I've got a multi-project ASP.NET Web Forms Application solution. I need to share a master page (3 files), some user controls and some images, scripts and CSS files out to the other projects in the solution.
I have already created a package using the NuGet Package Explorer per the documentation:
http://docs.nuget.org/docs/creating-packages/using-a-gui-to-build-packages
My current problem is this: I have updated the shared files in the root project and now I want to update the package before pulling it into the other projects (package currently in a local folder on my dev machine). How do I do this?
If anyone has some getting-started-quickly NuGet links, please share as the official docs just aren't doing it for me.

create the package again with a new version aka if the orginal is 1.0 make this 1.1 and NuGet will pick up the update.

The NuGet file is ultimately just a zip file. You can update entries using anything that can update a zip file. Such as something like
using System.IO.Compression;
using System.IO.Compression.FileSystem;
// EG: AddOrUpdateZipEntry("mypackage.nupkg", "my.dll", "bin/my.dll")
void AddOrUpdateZipEntry(string zipFilePath, string contentsFilePath, string entryPathInZip)
{
using (var zip = ZipFile.Open(zipFilePath, ZipArchiveMode.Update))
{
zip.GetEntry(entryPathInZip)?.Delete(); // Remove any existing entry first.
zip.CreateEntryFromFile(contentsFilePath, entryPathInZip);
}
}

Are you asking what you need to do to update projects that are already using the package?
The key thing in this kind of scenario is simply versioning. The new version of the file will be sub'd out. Bundle up the package again with a new version number and then run Update-Package from the package manager console in VS.
You may also want to consider a couple of discreet packages, rather than one straight one. If you want to update a couple images or a CSS file, but not the MasterPage, it might work best to have a couple smaller ones.
Use the PM Explorer (from the post you mentioned) to open a couple packages from the NuGet main repository, in particular, jQuery 1.5.1 and 1.6.x and have a look, as these will be doing very similar things. No real magic needed!
Cheers.

I've already done it before. You just have to increment the version of your package, inside metadata of .nuspec file.
In my case, my packages names are '[name].[version].nupkg' so I save my new package as '[name].[version +1].nupkg' as well.
The update apears in 'Manage nuget packages' updates section.

Related

Changes made to Rocket.Chat are not included after building

I'm new to developing with Meteor and node-based apps.
I intend to create a PR for a problem i noticed in Rocket.Chat.
I git cloned the Rocket.Chat dev branch and made a change to a certain file:
https://github.com/RocketChat/Rocket.Chat/blob/develop/packages/rocketchat-oembed/client/oembedImageWidget.html
After that i ran the build-script successfully. My build started, but the change is not included.
Using the Chrome Dev Tools to inspect the change, i still see the original unchanged code.
I know it's a rather generic question and i'm sure the solution is kind of stupid, but any idea why ?
Thank you.
Kind regards
It looks like the file you modified is in the packages directory. This is dealt with differently.
Check the .meteor/packages files to see if this package is referenced, if it is, then it will install the package from the atmosphere package management system.
Here the steps required to make your changes work...
1) Edit the .meteor/packages file and change the reference to rocketchat:oembed to be simply oembed
2) Edit the file packages/rocketchat-oembed/package.js and do the same thing, change rocketchat:oembed to be simply oembed
Package.describe({
name: 'oembed',
version: '0.0.1',
summary: 'Message pre-processor that insert oEmbed widget in template',
git: ''
});
I think you can leave the directory names as is.
Meteor will now use your local package instead of going out to get the published version of it
In addition to #Mikkel's answer: I think you don't have to change package name, but just change its version. That should be enough for Meteor to rebuild this package from its source and you won't have any dependency issues.

Create Visual Studio project from existing Umbraco Website

So this is my problem:
I currently have an existing Umbraco Website, v7.2.1, not installed with Visual Studio, so there is no solution file.
I want to migrate this site to the typical Umbraco solution, so I can run it locally, and make it more familiar to my way of working with Umbraco.
I have tried to create an .NET project and installed the Umbraco Core nugget (also version 7.2.1) followed by importing the website. With no avail.
I rather not move everything manually into a new Umbraco solution.
Help me Umbraco community, you're my only hope.
It depends on how much customization has been done, I think?
I would probably install UmbracoCms -version 7.2.1 (not "just" Core) from Nuget into a fresh solution, build it and then point the connection string to the existing database (if not an .sdf file already). Then you'll (hopefully) only have to copy over folders like /Views and /config plus whatever scripts/styles folder you have, I think? Once copied over, all you have to do is include the folders in your project, and voila.
Unless that too is too much "manual" work? ;-) I'm not sure if you could get by with creating a package on the original site (with templates, doctypes, content, styles, scripts and everything) and importing it into a new, blank site :-s
Again, if you have installed any packages either via Umbraco Package Repository or Nuget, or indeed if you have made changes to /umbraco or /umbraco_client, I don't see any other way to do it other than manually copying them over.
Try doing a, complete, fresh install of Umbraco 7.2.1, then literally copy all the files from the current site, and simply paste and replace them into the new Umbraco solution. That should work.
This is indeed "manual work", but you can literally move all files at once and just overwrite the existing ones in the newly created solution.
Good luck.
Like Jannik said, it depends how much you've build around your current solution and what exact results you're expecting.
Option 1 - WebSite project
You can easily create an empty solution in VS and add new Web Site project (ASP.NET Empty Web Site). Then, paste and include all the files from your current location. You'll have new solution and VS project with your files / website.
Option 2 - ASP.NET Application
If you would like to have it as a ASP.NET app, I would follow these steps (almost the same as Jannik's steps described above):
Create empty ASP.NET Web Application in Visual Studio.
Nuget: Install package -UmbracoCms -version 7.2.1
Repoint connection string to current site database (or replace SDF database file in App_Data directory if it was on SQL CE).
Analyze what packages you've used and try to also install them from Nuget (if they have Nuget packages). If not - move them manually (DLLs etc.).
Copy all static files from your current site (App_Plugins, Configs, Views, Partials, MacroScripts, Scripts, CSS etc.).
But I see also the 3rd option, which may interest you especially if you want to kill two birds with one stone and update Umbraco to the latest version at the same time.
Install uSync and uSync Content Edition on your current website. Perform Full Export. Read more: https://our.umbraco.org/projects/developer-tools/usync/.
Create empty ASP.NET Web Application in Visual Studio.
Nuget: Install package -UmbracoCms
Install uSync and uSync Content Edition on your new web app.
Install all packages used in the previous version.
Copy files from uSync folder in old website and place them into the new one. Perform Import / Full Import.

Nuget does not update Package References in ASP.NET website

About: I have a ASP.NET website (not Web project) with 3 class library projects in the solution. Earlier I was using SVN but now Git is used source management. I have installed the git locally on a computer (used as server) and using it for merging the source code from other developers. Also, I am using Visual studio 2015 community edition which provides the tools to work with git.
Problem: After cloning the project from the master repository, I build the project to run it. Building the project shows a dialog box saying "Package Restore is in progress". This process creates a folder named "Packages" and that folder includes every package listed in the packages.config file. But after restoration completes, the project throws the following exception:
This exception shows for each package (Autofac here).
The type or namespace name 'Autofac' could not be found (are you missing a using directive or an assembly reference?)
Work around To Solve this problem, I need to uninstall each package and installed it again and problem is solved. This thing I need to do again and again for each developer machine, which is frustrating and time consuming too.
Does anyone has faced the same problem working with Nuget, git and website in ASP.NET.
I faced a problem like this before. In my case, the reason was that I changed the project path (moved the project to another directory), and the path of the packages directory (that contains the NuGet packages) was stored in the csproj file for the old path, that is VS cannot restore NuGet packages. The solution for this was to edit the csproj manually and make it referring to the correct new packages path.
If this doesn't work for you, you can still use your workaround, but using the following PowerShell command (in NuGet Console) for simplicity:
Update-Package -reinstall -Project Your.Project.Name
Note: project name doesn't contain csproj extension, just the project name
It is good practice to not put third party packages into source control. It bloats your repository (even on a large web application, the size of the external packages will massively out weigh your code).
If NuGet package restore is slow, you could look at using a local cache (this can be as simple as a shared folder) or a better internet connection.
That said, you should only have this problem once per machine. While the packages are downloading you could be giving the new team member an overview of the design…
Make sure that all of your projects are using the same target framework, when this isn't done you can often get the
type or namespace [name] could not be found
warning.
To do this, right click each of the projects in the solution explorer > Properties > Application tab > Target Framework. They should all be the same or there will be incompatibilities between the references in your projects. Here's a question regarding this, hopefully this helps.
The main reason is there no Autofac reference in packages.config file.
When you see on the screen Restore packages message box this mean that nuget package manager is trying to install all the packages which are missing in the package folder.
Try to do this step:
In Visual Studio Solution Explorer pick the project and via context menu pick Unload project
After project was unloaded via context menu pick Edit your project
Go to section group and find you Autofac Reference section
If HintPath doesnt looks like ..\packages\Autofac.4.1.1\lib\net45\Autofac.dll (Actual for 4.1.1 version) remove the Autofac reference Item
Save csproj file and reload project
Install Autofac via NuGet Package manager
Commit and push changes to git repository
Had the same problem with VS 2019. In ASP.NET, packages are updated via the .refresh files that appear in your bin folders. If these aren't checked into Git, they wouldn't be copied down to your cloned repro.
I added the .refresh files for all of my package dlls, made sure the versions and paths in the .refresh files were correct, and now everything updates as expected.

How can I manually update jQuery UI installed via NuGet package?

Situation
I am working on an ASP.NET Web Forms project that was generated using the default Visual Studio 2012 project template. I have since then used NuGet to install jQuery UI version 1.10.0.
I need to update to jQuery UI 1.10.1 because there is a bug fix I need. According to the website, 1.10.1 is the current stable version. However, there is not a NuGet package available for this version!
I don't know why the NuGet package would lag behind the latest available stable release from the jQuery UI team on their website. (Yes, I realize there is probably a different team managing the nuget package itself... but it still seems like this needs to be kept up to date.... or the value of installing jQuery via NuGet is very limited.)
Question
How do I update jQuery UI (installed as a NuGet package) manually to 1.10.1 on my project?
I have already downloaded the latest 1.10.1 javascript files. Now.... when I look inside my ASP.NET Web Forms project, I see in the following files in the Scripts folder:
So what should I do here... delete the following two files?
jquery-ui-1.10.0.js
jquery-ui-1.10.0.min.js
...and replace with these new files?
jquery-ui-1.10.1.js
jquery-ui-1.10.1.min.js
This doesn't seem like it would work.
The way jQuery is being include in my masterpage (from the default template generated by Visual Studio 2012) is like this:
That JS bundle you see above, called "jquery.ui.combined" is auto-magically generated by some kind of hidden code. Go ahead and look through your project... you won't find anywhere obvious this bundle is defined. So if I add the latest JS files... it seems I have no way to define that they get used or bundled at all. They aren't the version that the NuGet package logic/code would be expecting!!!
Any ideas?
Another potential problem
When I downloaded jQuery UI 1.10.1, it also came with jQuery Core 1.9.1. As you will see above in my Scripts folder, it appears as if jQuery UI 1.10.0 goes hand-in-hand with jQuery Core 1.9.0. If I update jQuery UI..... do I also need to update to the matching jQuery Core as well? (These are separate NuGet packages)
Please answer this specifically
I would like for the answer to explain how to manually update the version of jQuery UI installed from NuGet package.... on an ASP.NET Web Forms project.
I think this would be useful so that in the future a developer can pull down the latest bug fixes as soon as they are included in a stable release on the jQuery UI website.... without needing to wait for the package to show up on the NuGet feed.
The jQuery UI team hasn't uploaded the version 1.10.1 for their package. I'm afraid you just have to wait until they release it.
If you can't wait, you can uninstall the current version of jQuery UI first, and then manually add the script files of version 1.10.1 into your project.
Work-around... although it seems like a bad approach....
I just opened up these files....
jquery-ui-1.10.0.js
jquery-ui-1.10.0.min.js
...and replaced the contents with the contents from these files:
jquery-ui-1.10.1.js
jquery-ui-1.10.1.min.js
I left the file names the same as they were. So even though the JavaScript files are named as version "1.10.0".... they are actually holding the code for version "1.10.1".
One of the reasons I think this might be a terrible idea
What happens if some other developer attempts to pull down my code from source control... and they use NuGet Package Manager to restore the packages they did not have yet. Wouldn't it pull jQuery UI nuget package and replace the JavaScript files I have modified with the ones from the nuget package? Then the page would start exhibiting the buggy behavior again, and no one would know why.
At the very least.... for now I can continue development with the bug fixed! It was very annoying... the overlay was appearing on top of the dialog and I couldn't interact with the page. Here is the bug that was fixed: http://bugs.jqueryui.com/ticket/8984
Go To : Visual Studio -> Tools => Library Package => And Package Manager Setting
Window opens Having Options as in Screenshot
Click On Add (+) Button At Right Top And Inside Source Browser To Your Folder Location of Whatever Package of Nuget You HAve. Name is Whatever You Want And Press Ok
You Can See Now Your Package Into Extensions And Updates Window
To Install In Current Project
use Package Manager console : Install-Package ANd your package name

Updating MiniProfiler.MVC3 NuGet package after editing MiniProfiler.cs in App_Start

In the MiniProfiler.MVC3 NuGet package, it creates a file in App_Start that is used to control MiniProfiler settings (the SqlFormatter to use, modifications to the ViewEngines, when to start MiniProfiler, etc.).
There are a lot of TODO comments in this file talking about how to change the code to perform how you want. This is great, but when the NuGet package is updated, it will see that I've changed the file and not pull down the updated version. The problem here is that I lose any updates to that file, and depending on what else updated in the package, making it unusable (for example, when upgrading MiniProfiler.MVC3 from version 1.9 to version 2.0.1 after modifying MiniProfiler.cs in App_Start, the project will no longer build because of needed changes to that file in the 2.0.1 version).
What is the best way to handle this? Should I create my own file in App_Start and not modify the one in the NuGet package, ensuring that I will always get the full update when upgrading to the latest version of the NuGet package?
You could backup the file in App_Start, update it, then merge the files manually, or using a merge tool. You'd probably end up doing this anyways if you're using source control.
Quick-and-dirty: create the file you want. Then copy over/merge every time you upgrade with nugget. Or with every compile. The added build time is negligible.
Slightly better: use the precompile event in visual studio and compare the files. If they differ - either copy over or tell the user. I can't figure out a way to show a message box, or similar, on the top of my head but one could always create a new file with a compilation error and some text nearby "discrepancy in the xxx file".
try using mercurial queues. You can get your code to the point you want (excluding the file you refer to), and then commit. Make changes to your file, and push it to a queue. Make sure to exclude it from any future updates (manually), and then when you want to update your package, pop it off your code base. This will make it look like it used to, and run the nuget update. Then you can push the queue back to the code, and your changes will re-applied. It might take a bit of fiddling, but worth a look.
For reference:
https://www.mercurial-scm.org/wiki/MqExtension
https://www.mercurial-scm.org/wiki/MqTutorial
https://developer.mozilla.org/en/Mercurial_Queues

Resources