Is it possible to modify VS project file during NuGet package installation? - visual-studio

I'd like to create a custom MSBuild task and distribute it as a NuGet package. To enable my task, the visual studio proj file should be modified.
Is it possible to add my code sections to the proj file when installing the NuGet package?

You can do this using Powershell. It is possible to unload you project, edit the project file and reload the project.
Scott Hanselman did this here: http://channel9.msdn.com/Events/MIX/MIX11/FRM09
If you find a package that does what you want, you can open the nuget package using ZIP and see the powershell scripts. Thats a good starting point to learn that stuff.
hope that helps

I think you are better off using the NuGetPowerTools package as answered in this question:
Adding a custom build step with a nuget package
This package handles all the Visual Studio automation.

Related

Difference in nugets processing via `dotnet add package ..` vs nugets adding via visual studio UI

I need to use native c libraries in my library(that supports several Core TFs and .net framework) which is published via nuget. I configured it via .csproj file and runtimes folder. But I noticed that when I consume my NuGet via dotnet add package .. in some cases, the native libraries are not copied into the expected folder after consuming, however when I use the VS UI Nuget package manager->Manage Nuget Packages for Solution, all files are placed into correct places.
So, I assume that Nuget package manager makes more steps than just call dotnet add package .., but it's unclear what exactly happens, any help will be appreciated.
Actually, dotnet add package does the same effect as Nuget package manager UI in VS IDE. They simply install a Nuget package into your project and there is no difference. No additional operations will be performed. Like add some xml node in
So I think there is something else wrong in your project.
Please check under tips to troubleshoot your issue:
1) clean nuget caches first or just delete all cache files under C:\Users\xxx(current user)\.nuget\packages.
2) And if the runtimes folder does not exist under your project, I think it is controlled by dependency assets. Like ExcludeAssets=runtime or native. It will prevent the function of runtimes folder. Please see this official document.
So after you finishing installing the nuget package, you should check your csproj file, and make sure that there is no such like
<ExcludeAssets>runtime;native</ExcludeAssets>
under PackageReference node.
If there is any this node, please delete it.
3) delete bin and obj folder. Then rebuild your project to test again. Or if you use dotnet command line, you should additionally add dotnet build command. In my side, I run dotnet build -p:platform=xxx;Configuration=Release.

Using NuGet without .sln or .csproj files

I am currently working in a UFT project, using the VBScript language.
This project does not have a .sln or even .csproj files, because of this i am using the nuget.exe.
I want to use NuGet to manage binaries. I am already able to push a NuGet package to the repository, however I can not update or install it.
This is how my project looks like(I know its a bit different and is located on c:):
So it happens that I searshed on the internet but there are not even one project that looks like mine, most of them are done on Visual Studio.
Could you help me on how to use NuGet in a project like this one?
Thanks!

Add project in solution using NuGet

Currently I have a requirement to add multiple projects to a solution via NuGet package. I know that adding files to the solution is possible as described in this link, but I'm not able to add project in the solution. I wan't to know that it's possible or not and if possible how i achieve this. Any help will be greatly appreciated. Thanks.
This is not really possible using a single command. If you are using install.ps1 scripts, you can choose to modify the sln file in the script.
E.g If you open a sln file that has a project you can see the following
Project("{Project Guid}") = "ProjectName", "Relative path to project", "{Project Guid}"
In your install.ps1 script, you can crack open the sln and insert a similar entry for each of your projects during install.
Do note, this is probably something you will have to use nuget commandline for,
nuget install
since there is no easy UI way of installing NuGet packages to a solution in VS 2015.

Can Visual Studio 2012 save custom NuGet package sources in the solution?

I am looking at setting up a custom NuGet repository for my organization and I would like the ability to have the package sources saved against the solution so that other developers don't need to manually set up their own package sources, is this possible?
So my problem was that in order for the .Nuget folder to be created automatic restore needs to be enabled by Right clicking on the solution in VS and choosing "Enable Nuget Package Restore" rather than relying on the visual studio option.
Yes you can, if you make use of the MSBuild based package restore functionality. Detailed steps can be found in this blog post: http://xavierdecoster.com/nuget-package-restore-using-solution-specific

Can WiX source refer to NuGet packages from another projects in solution?

I have a solution with two projects:
.NET application
WiX setup project.
I know, that it is possible to refer to project output in WiX source ($(var.WindowsFormsApplication1.TargetFileName)).
Now I've added a NuGet package reference to my .NET application. So, I want to bring NuGet package content into my setup.
Is there any way to do this instead of adding files manually?
I don't believe there is any linkage. I know what nuget is but I haven't used it much because it's more about brining your .NET dependencies into scope then software distribution. Depending on how nuget lays the files down you might be able to do something like $(var.SomeProject.TargetDir)nuget_fetched.dll.
This is assuming that SomeProject uses nuget in such a way that the references are copied locally and available in the Outdir of the project.
I wrote a Resharper live template to cut out a lot of the typing involved in adding the files, but essentially I've just added the files manually. Creating a Wix component per nuget package keep things neat.

Resources