nuget package split-out config from library - dll

Is there any advantage to breaking-out library config-settings files into a separate package ?
Let's say we package-up a lib + config , and then update it :
MyLibrary.1.0 package
contents : MyLibrary.dll v1.0 + MyConfig.xml (original)
MyLibrary.1.1 package
contents : MyLibrary.dll v1.1 + MyConfig.xml (revised)
Project A
subscribe MyLibrary.1.0 package ( MyConfig.xml original )
Project B
subscribe MyLibrary.1.1 package ( MyConfig.xml revised )
Alternately we can split-out dll and xml into separate packages :
MyLibrary.1.0 package
contents : MyLibrary.dll v1.0
MyLibrary.1.1 package
contents : MyLibrary.dll v1.1
MyConfig.1.0 package
contents : MyConfig.xml (original)
MyConfig.1.1 package
contents : MyConfig.xml (revised)
Project A
subscribe MyLibrary.1.0 package
subscribe MyConfig.1.0 package ( MyConfig.xml original )
Project B
subscribe MyLibrary.1.1 package
subscribe MyConfig.1.1 package ( MyConfig.xml revised )
The only advantage I can see is that with configs in separate packages , it's possible to update to latest config without updating to latest library - but it's unlikely that would ever be useful. And we lose the strong-coupling of lib and related config settings.

Related

Transitive reference in a NuGet package

I have a NuGet Package: My.Framework
This package has a method MyMethod Using Prism
My Package is used in another project MyProject calling MyMethod
Prism <-- My.Framework (MyMethod) <-- MyProject
My problem is when I execute MyProject it fails because the Prism.Dll is not present in the build folder.
Do you know how I can instruct MsBuild to Copy the Prism.Dll in the build folder?
Ideally, I would have the information defined in My.Framework package.
Update
MyFramework Package reference correctly Prism:
You need to ensure your package's dependencies are defined in its nuspec file

how to use Microsoft.VisualStudio.Web.CodeGeneration?

I find that The package:Microsoft.VisualStudio.CodeGeneration has over 20,000,000 downloads in the nuget.but I can not find any doc.
how to use it?
any articles about it?
What does this package do
Basically, the package offers a single command to generate code:
dotnet aspnet-codegenerator {name}
You can find the source code here.
How to use the package
We don't use the Microsoft.VisualStudio.Web.CodeGeneration directly unless we're creating a new command to generate code.
Because it is a command library for generic purpose, concrete commands are defined in other packages. For example, the dotnet aspnet-codegenerator controller command is defined in Microsoft.VisualStudio.Web.CodeGenerators.Mvc. And the command dotnet aspnet-codegenerator identity is also defined in the CG.MVC package.
Usually , since this package is a generic purpose library, you won't reference this package directly. Instead, You'll add the package Microsoft.VisualStudio.Web.CodeGeneration.Design. Be aware the Microsoft.VisualStudio.Web.CodeGeneration.Design package has a dependency on Microsoft.VisualStudio.Web.CodeGenerators.Mvc, and the Microsoft.VisualStudio.Web.CodeGenerators.Mvc depends on Microsoft.VisualStudio.Web.CodeGeneration:
Microsoft.VisualStudio.Web.CodeGeneration.Design
|
|(depends on)
|-----------> Microsoft.VisualStudio.Web.CodeGenerators.Mvc
|
|(depends on)
|-----------> Microsoft.VisualStudio.Web.CodeGeneration
Be aware the Microsoft.VisualStudio.Web.CodeGeneration.Design is automatically added into your dependencies when you use Visual Studio to scaffold a controller/identity.
If you're using a VSCode/CLI, you need to manually add such a package reference. See https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-model?view=aspnetcore-3.0&tabs=visual-studio-code#add-nuget-packages
What #itminus says. I think the reason it has so many downloads is from the clear error message when you try to use dotnet aspnet-codegenerator without Microsoft.VisualStudio.Web.CodeGeneration.Design NuGet.
As of 2021-08-27 it has 90,672,569 total downloads.
https://www.nuget.org/packages/Microsoft.VisualStudio.Web.CodeGeneration.Design/
Example error:
Building project ...
Scaffolding failed.
Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a
NuGet package reference. To see more information, enable tracing by setting
environment variable 'codegen_trace' = 1.

Auto update nuget package from a local folder

My .NET Core project references a class library from another project.
I publish the nuget package to a local folder like this:
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration% -o D:\\mynugetpackages\\%project:Name%"
]
}
Then I add a reference to another project from this folder.
Every time I update my class library, I have to manually go to manage nuget packages and then update nuget packages from Visual Studio in the referencing project.
Is there a way to automate this, so that when I make an update and publish latest nuget package, the referencing project will automatically update to the latest update?
No, it's not possible for Visual Studio to automatically detect that a package has been updated (in a local or remote source).
You could write a script to run nuget update in your target project to grab the latest packages, but you'd still likely have to kick off the script manually. This would at least be faster than manually clicking through the NuGet GUI in Visual Studio.
Another option is to put the class library in the same solution folder structure as your main project, and reference it as a project dependency:
"dependencies": {
"MyClassLib": {
"target": "project"
}
}
This only works if you're able to adopt this folder structure, though:
src/
MyProject/
MyClassLib/

Publish type declarations outside #types

I have created an npm library but I don't want to publish it in the public repository (So I cannot use #typings npm package to put my typings there). On the other side, I don't want to put .d.ts file into that package but wanted to publish another package called lib-typings.
Is it possible to consume lib-typings for a library called lib in Typescript 2?
As cartant said, property typeRoots in tsconfig.json is for addressing this problem.

NuGet does not copy dependencies with higher version than the one specified

I have a Web project (W) which has a reference to a Class Library project (C):
W --> C
C references N1:
C --> N1
N1 is a custom NuGet Package that has two dependencies (both are also custom NuGet packages): N2 e N3, targeting version 2.1 or higher and 3.4 or higher, respectively.
N1 ---> N2 (>= 2.1)
`--> N3 (>= 3.4)
When I added the N1 package to C, N2 had a 2.2 version available, so NuGet got that one, instead of 2.1, as it was expected to do.
The problem starts here: when I build W, N2 is not copied to W's bin folder. I googled a bit, and found out that Visual Studio does not copy dependencies that are not "first class dependencies", that is, dependencies which are not used directly by C, to W's output folder. I can confirm that, because when I add the method below to any class in C, N2 gets copied.
private void ForceCopyOfN2()
{
var someObject = new N2.SomeClass();
}
Also, without the hack above, if I downgrade the version of N2 to the same version that is specified by the N1 package dependencies (i.e. from 2.2 to 2.1), N2 also gets copied.
So I am guessing this is an issue with NuGet. Has anyone experienced anything like this?
I was not able to repro this with VS 2012 targeting 4.5, here is what I tried
1. Create new web application project
2. Create new class library
3. Add reference from web application to the class library
4. in class library
PM> install-package windowsAzure.servicebus
Attempting to resolve dependency 'Microsoft.WindowsAzure.ConfigurationManager (≥ 1.7.0.0)'.
You are downloading Microsoft.WindowsAzure.ConfigurationManager from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkID=235167. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'Microsoft.WindowsAzure.ConfigurationManager 1.7.0.3'.
You are downloading WindowsAzure.ServiceBus from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkId=218949. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'WindowsAzure.ServiceBus 1.8.0.0'.
Successfully added 'Microsoft.WindowsAzure.ConfigurationManager 1.7.0.3' to ClassLibrary1.
Successfully added 'WindowsAzure.ServiceBus 1.8.0.0' to ClassLibrary1.
5. where service bus is dependent on configuration with >=1.7 and 1.8 version of configurationmanage is installed
6. build the classlibrary and then webapplication solution, refresh the solution explorer. For my solution I saw classlibrary, servicebus and configurationmanager are dropped in the bin folder. (not sure why but i saw the files dropped after I tried building classlibrary once again after adding the reference)
Is there something I am missing here?