How do I know where NuGet puts my tools? - c#

I have a project with some protobuf files. I want to compile these files to C# as a pre-build step.
So I add Grpc.Tools as a NuGet package to the project. And lo and behold, the tools are downloaded inside the solution's packages folder: packages/Grpc.Tools.1.6.1/windows_x86/protoc.exe.
Our CI server, on the other hand, uses a linux docker container (microsoft/dotnet). Is there a portable way to specify where to find the protoc compiler? Preferrably I would like to just ask the system: dotnet where Grpc.Tools or something.

I had a similar issue, in my case I wanted to pack C# code using ExcelDNA tools that come with the package. The post build event was added as part of the package install, but depended on the package folder been located in the solution folder, as you say. Porting the code to Net Standard we realised that the new version of nuget cannot deal with this specific issue of post build events which require the package tools to be in some folder relative to the solution or project. So to directly answer your question see here.
However you may not find that very useful if you want to do a post build event from the solution? If you are using jenkins et al and have a seperate step for packaging then the above should work fine.
There are a couple of ways around it. Most simply you can add the tools to source control, and then manually edit the post-build events. Depending on how you feel about that.
Secondly you can force nuget to resotre the packages locally and not in the system wide cache folder. You can do this through the Nuget.Config file. I have not got the specifics to hand, but if you cannot figure it out I can look in my old code.

Related

Where can I find SQLite.Interop.dll files and bundle?

I am working on a .Net application and planning to use SQLite as its back end.
I ended up with “Not able to load SQLite.Interop.DLL”
Then I found the documentation in http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
But I’m not able to find a zip that contains all the essential files mentioned in the above documentation. All the files are either separated or in NuGet packages.
Can someone help me out to find a zip the contains the following DLL files as a zip in a single zip ?
<bin>\System.Data.SQLite.dll
<bin>\System.Data.SQLite.Linq.dll
<bin>\System.Data.SQLite.EF6.dll
<bin>\x86\SQLite.Interop.dll
<bin>\x64\SQLite.Interop.dll
I don’t want to reference a NuGet package with my project, as I’m building this application using ANT and signing this is a separate build server that I’ve setup to compile and check the MSI files and it’s generation.
I’ll add a copytask to my ant build and copy all the dll files to the project before building it into msi. The only thing missing is a zip that contains all these above essential files.
PS : I need this application to work on both x86 x64 arch.
I've Searched around almost many sites and like #Blindy and #Selvin said there is no way around NuGet packages it seems.
Hence, I've downloaded the NuGet package from http://system.data.sqlite.org/downloads/1.0.113.0/System.Data.SQLite.Core.1.0.113.0.nupkg here which seems to contain SQLite as well as Platform Interop files.
Once I've downloaded these,
In VS, Tools -> Options -> NuGet Package Manager -> Package Source -> Added a new source as my local folder.
I've placed the downloaded package inside this folder
Project -> Right Click -> Manage NuGet packages -> Under the browser tab, I've selected the RHS filter as the source I've added in the previous step and the package I've downloaded was listed under here.
I Installed them and this created a packages folder inside my solution directory.
Then I was able to use System.Data.SQLite in my application. But it still threw "Could not load SQLite.Interop.dll". To tell the builder that you have to use the interop files, open the csproj file for the project and add,
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
And then this started working properly. I might use this as a structure instead of running a copytask in ant I guess.
Thanks to #Selvin and #Blindy

How can I programmatically find a DLL restored by Nuget?

After a user does a dotnet add package <SomePackage>, the DLL will be installed to a path similar to:
C:\Users\USER\.nuget\packages\SomePackage\1.0.2\lib\netstandard2.0\SomePackage.dll
How can I find this path programmatically? I see there's some information in the obj/project.assets.json that I could parse, and also an interesting DependencyContextJsonReader class under the dotnet github organization.
However, there's no documentation or discussions about this that I can find, and I'm not sure if that's because I'm taking the wrong approach.
Some background:
I'm writing a tool that can scaffold C# projects. It uses a combination of the dotnet command line tools, and the Roslyn Workspace APIs to interact with the generated project. I'd now like to allow the user to install Nuget packages into this generated solution. I invoke dotnet add package SomePackage which works fine, and now I'd like to add the DLL to the Roslyn Project object using the AddReferences API, which requires the actual DLL.
I found a way to do this using the nuget client libraries.
Essentially, rather than shelling out to the dotnet add package command, I can use the NuGet client libraries directly from my application to install packages. I then have access to the full path via the PackagePathResolver.GetInstalledPath method.
Martin Björkström's post, Revisiting the NuGet v3 Libraries, goes into much more detail, and a fully working code sample from Martin is available in this gist.

Managing Telerik .NET references in a Git environment

We've got about two dozen projects, which all use different NuGet-packages and a bunch of Telerik WPF libraries, the latter are usually added by GAC, which on its own does not add a hint path to the csproj-File. (Good)
As soon as we use Telerik's upgrade wizard to simultaneously upgrade the references of all projects, Telerik starts copying the files to a local lib folder next to the bin folder and adds hintpaths, which do not exist on other developers machines AND need to be discarded before pushing to Git every time. (Bad)
BTW: We regularly get the same problem (regarding hintpath) with the Spire NuGet-Package.
Now we came up with some suggestions, which we internally valued differently and therefore did not come to an accord:
Keep discarding the chunks containing the hint path
Ask Telerik to fix the wizard
Check the libraries into Git
Add Telerik libraries using their NuGet server
Create a Libaries-Path we manage by hand, maybe as a network drive
What's other peoples approach to handling those issues?
I'd go for "Check the libraries into git".
Rationale: when a developer (or CI system) checks out your project from source control, he should be able to build it right away without having to install dependencies like GAC assemblies.
You need to use NuGet for that, it's the easiest and most organized way, you should not have a problem for other developers when you install a new package as long as you are committing package.config file, in this case any one will do a build of the solution visual studio will automatically restore NuGet Package.
Make sure to set your NuGet settings as below image shows:
Don't use the Telerik wizard. Add the Telerik dependencies using NuGet. They have a private NuGet repository. See the tutorial here.

How to see source code from github in Visual Studio IDE, but compile with dlls from Nuget?

Nowadays there's a lot of great open source packages and frameworks for all sorts of uses. Let's take for example, ASP.NET Core MVC and Newtonsoft.Json.
Those are shipped in Nuget packages, which are stripped of the source code.
I think many of you can remember a lot of situations in which one would like to see the source code freely available on GitHub (to help debugguing some issue), but was forced to do one of the following:
Be lazy and just forget about it, or continue debugging your issue with a popular library treating it more like a "black box";
Go to the browser, type github.com and search the source code without the mighty advises of the Visual Studio IDE;
Spend 5 minutes, clone the repository to the local drive and look at it with IDE;
Spend even more time while compiling the source code, deinstalling all of the nuget packages of interest from your projects and instead, hooking up directly to all of the freshly compiled assemblies (which are not always one-to-one to Nuget package).
This last option is the most viable, but you're left with a lot of time spent and you can't just push this to your repository or deploy the compiled code anymore. Other developers won't find those relative paths to the dlls and customers may end up with wrong versions of nuget packages baked in the deployment package.
Is there a fifth option which has all the pros of the fourth, but none of the cons? I imagine this being done by an IDE in an isolated fasion, i.e. no modification to my .csproj and package.config files, but the "Go to definition" & "Find all references" features and debugging should work as if I'm hooked up to the real stuff.
Yes, I'm pretty lazy.
Please pack the package as symbols package and then put the PackageName.Symbols.nupkg file with the ProjectName.nupkg file on the same package server after you downloading the package source code. I’m using following steps to debug my NuGet package source code in Visual Studio IDE.
Create my NuGet package project and implement the function that I want. In your situation, you just need to download the package source code from Github.com.
Build the project in your Visual Studio IDE, it will general a dll file and a pdb file in bin\Debug folder.
Download NuGet.exe and run this command to pack the source code project to package:
NuGet Pack MyProject.csproj -Symbols
There will generate two files, one is ProjectName.symbols.nupkg and another is ProjectName.nupkg. Upload these files to your NuGet Server. And you also can put them on your local driver.
Add your NuGet Server into your Visual Studio IDE through Tools -> Options -> Package Manager Console -> Package Source.
Open your project and install the package from the added package source.
Right-click your solution, choose Properties -> Common properties -> Debug Source Files, add the path where the PackageName.Symbols.nupkg file with the ProjectName.nupkg file stored on your local machine.
Now when your start debug your project and press F11 step into one function in your installed package, it will step into then package source code.
as mentioned in one of the comments, there is a VS extension that does this:
Nuget Reference Switcher (select one that matches your VS version to install), for more info, you can read its wiki on github.
here is what I usually do:
git clone the source repository
add the open sourced .sln/.csproj to your own solution:
run nuget reference switcher extension
This is equivalent to your step 4, but a lot less work since the heavy lifting is done by the extension.

Open Source projects with dependencies

I have a question regarding c# open-source projects and dependencies. For example, I am currently working on a few projects. One is a C# project that produces a class library with specific functionality. This project should be hosted as other projects will find this functionality useful.
The next project I'm working on requires a reference to the class library project which is under separate version control.
So how can I structure an open-source c# project with a dependency to the class library project without including the source code of the class library project?
Any example projects to study would be great too! :) Thanks in advance!
If the open source depency is on listed on Nuget then the easiest way is to add the Nuget package, and make sure your packages folder and packages config file is included in the project.
Unless you want the actual source, then this is the easiest way to add binary dependencies. It includes the PDBs so you get the lines of the original source code.
Include a cmake script to gather dependencies in the application source code. The cmake script will check for dependencies, and any that are missing will be downloaded.
You could experiment with the cmake script being a pre-build step in the solution; But for now dependencies are updated manually.
The script is the same no matter which system it is on, which is the beauty of cmake's script mode.
Although this is a bit clunky, it seems about the best way to include a source-code version of an external dependency which is not a part of the applications version control.
as an example, you can get a launchpad project:
bzr branch lp:~brian-sidebotham/+junk/valverschatcam
from the root of this project, simply run:
cmake -P build.cmake
Obviously the script should probably be called deps.cmake or similar instead of build right now.

Categories

Resources