Leading-dot files missing from custom Visual Studio template - gitignore

I've created a custom Visual Studio template containing an ASP.NET Core+angular application. But when I create a new project using this template, the files starting with . are missing from the generated project.
These are the files in the ClientApp folder of the template project:
But when I package the template project, install them using
dotnet new --install MintPlayer.AspNetCore.IdentityServer.Templates
These files are missing from the generated project:
I've already taken a look at the following, but without success:
Missing .lib files from exported Visual Studio template
When I run
dotnet pack --configuration Release
I can see the following printed in the console:
C:\...\NuGet.Build.Tasks.Pack.targets(221,5):
warning NU5119: File 'C:\repos\Example.AspNetCore.Templates\Example.AspNetCore.Templates\Templates\Application\Web\ClientApp\node_modules\resolve\.editorconfig' was not added to the package. Files and folders starting with '.' or ending with '.nupkg' are excluded by default. To include this file, use -NoDefaultExcludes from the commandline [C:\...\Example.AspNetCore.Templates.csproj]
How can I include these files anyway in my package as "Content"?
References:
.NET project templates (angular/react)
Another example template repository
Third example template repository for .NET

Adding
<NoDefaultExcludes>true</NoDefaultExcludes>
To the root csproj file solved the issue
The spa-templates repository does the same

Related

Create a NuGet package with only javascript files

I want to create a NuGet package that contains only javascript. I have no assembly that needs to be built and included.
So to do this I created an empty solution in vs, and created an empty project. In the project I created a Scripts directory with my javascript files. I have a package.nuspec and a packages.config
When I run "nuget pack" commandline I get an error:
C:\MyProject>nuget
pack
Attempting to build package from 'TestProject.csproj'.
MSBuild auto-detection: using msbuild version '16.1.76.45076' from
'C:\Program Files (x86)\Microsoft Visual
Studio\2019\Enterprise\MSBuild\Current\bin'.
Error NU5012: Unable to find 'C:\MyProject\TestProject.exe'. Make sure the project has been built.
C:\MyProject>
If I try to build the project in visual studio, I get an error...
Program does not contain a static 'Main' method suitable for an entry
point.
...which makes sense because I made this from an empty project.
I am not trying to deploy the assembly, just javascript, can I stop it from trying to build somehow?
Don't use a project. Have have your .nuspec and javascript files in the directory, then run nuget pack. If the nuspec doesn't contain a <files> section, then it will just copy the filesystem structure directly into the nupkg.
Having said that, new ASP.NET Core projects from Microsoft's templates no longer use front end resources (html, javascript, css) from NuGet packages, but rather use either LibMan or npm, to be more in-line with what the non-.NET front-end ecosystem uses. I suggest investigating those technologies and using them if possible.

Error NU5012 - nuget pack unable to find path (/bin/release/MyProject/bin/release)

I'm trying to update my nuget package by running the command nuget pack -properties Configuration=Release but this gives me the following error:
Unable to find 'bin/Release/{project-name}/bin/Release'. Mae sure the project has been built
I'm not quite sure why it goes to my Release folder and then continues to go down to another Release folder as this doesn't exist? I'm quite lost here, and I'm not sure what to do.
TL;DR
For the new <Project Sdk="Microsoft.NET.Sdk"> .csproj file format, use dotnet pack to build NuGet packages, even if they target .Net Framework or if the project is multi-targeted. Run this from the directory containing your .csproj (and optionally a .nuspec)
dotnet pack MyProject.csproj -c Release
Note that by default dotnet pack places the output .nupkg in the /bin/Release folder, which is different from the current default folder where older nuget pack placed it.
I would suggest you don't create explicit .nuspec files for the new .csproj formats, since most settings can be set in the "Packages" tab of the new Project format. However, if you do have a .nuspec, then dotnet pack will also combine any .nuspec file matching the project name, allowing for the $ symbol substitution from the version and metadata set in your .csproj.
More Detail
I also experienced this problem - in previous versions, I typically use to use this approach to pack against a .csproj with the .nuspec file of the same name, so that I can use all of the $ tokens like $id$, $version$.
However when attempting this against the newer <Project Sdk="Microsoft.NET.Sdk"> csproj formats:
nuget pack {MyProject}.csproj -Prop Configuration=Release
I received the same error (note the "duplication" of bin\release):
Error NU5012: Unable to find 'bin\Release{MyProject}\bin\Release\'. Make sure the project has been built.
And if I tried packing against a .nuspec containing symbols (NuGet Version: 4.7.1.5393)
nuget pack {MyProject}.nuspec -Prop Configuration=Release
I just get the unhelpful message because nuget isn't able to resolve the $ tokens automatically.
Value cannot be null or an empty string.
Parameter name: value
However, by using dotnet pack instead of nuget
dotnet pack MyProject.csproj -c Release
I get to where I want to be, i.e. a multi-targeted NuGet package with the $ symbols in the .nuspec correctly synchronized from the .csproj (you can verify this by opening up the .nupkg file in e.g. 7zip and examining the final .nuspec file in the package root)
I had the same problem on a multi-targeted project (targetting both net452 and netstandard2.0).
My fix/hack was to add 'TargetFramework=net452' to the list of properties passed to Nuget, and manually adding the netstandard2.0-output to the files-section in the .nuspec-file
Hope someone finds a better solution
Part of Rune's answer (setting TargetFramework=net471 NuGet property)
and using NuGet version 4.9.1 (instruction here: https://stackoverflow.com/a/53614798/1813219)
was a way to go for me.
Actually I just solved the problem on my end. Nuget may not find hidden dll. Here is my solution:
Build the project;
Show all files in visual studio so you can see the hidden files, so that you can see the dll under bin folder;
Right click, open folder in file explorer, then copy it to current folder let them replace/ Or unhidden the files;
Do "Nuget Pack" again.

Creating nuget package for .Net Core library

I have a .Net Core library project which i want to share with all our other projects. These other projects are developed in Classic 4.6.2 and ASP.NET Core. I want to share it using Nuget package. Since package needs to be private i will be hosting it on our server. The .net core library project i am trying to publish has the following project.json
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
I followed these guidelines [here][1] to create a package
Created the .nuspec package manifest file using nuget spec command
Updated nuspec file as per the suggestion
Tried creating package with command nuget pack MyProject.xproj
got error
Please specify a nuspec or project file to use.
Looks like nuget does not recognize xproj So executed command nuget pack MyProject.nuspec
got warning
WARNING: 2 issue(s) found with package 'MyId'.
Issue: Assembly outside lib folder. Description: The assembly
'bin\Debug\netstandard1.6\MyProject.dll' is not inside the 'lib' folder and
hence it won't be added as reference when the package is installed
into a project. Solution: Move it into the 'lib' folder if it should
be referenced.
Issue: Assembly outside lib folder. Description: The assembly
'bin\Release\netstandard1.6\MyProject.dll' is not inside the 'lib' folder
and hence it won't be added as reference when the package is installed
into a project. Solution: Move it into the 'lib' folder if it should
be referenced.
I have already already looked SO post [here][2] and [here][3] but it couldn't solve my issue
If you have to use your own Nuget Server I would suggest that you actually use the nuget utility to push the package to your server. I usually write a small batch file that can be scheduled with build events or execute when I explicitly want to deploy new packages of the cross cutting concern portable class libraries.
The batch file could be something as simple as:
FOR %%I in (<PATH_TO_YOUR_DEBUG_FOLDER>\*.nupkg) DO nuget.exe push "%%I" -Source http://<NUGET_SERVER>/api/v2/package?replace=true
Note that by adding the replace query string at the end and changing your nuget config to allow for replacements you do'nt have to go through all the pain to reversion things.
Alternatively you could just make use of a private feed:
Create a folder where you want local packages to live
Add nuget config file to the root of your solution that specifies the private feed location
Then use a similar push command
Restart Visual Studio if the private feed is not visible.

Nuget package restore is not working on TFS build server

I followed this blog post and I expected Nuget to just work. It obviously has not. I get errors on all of my third party dll's that I expect NuGet to update automatically:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\
Microsoft.WebApplication.targets (182): Could not copy the file "bin\AutoMapper.dll"
because it was not found.
I have set everything up correctly and I have ensured that the solution has Package restore enabled. If I delete a package locally and build, NuGet restores that package for me.
I am not sure why it is not fuctioning on the build server though.
Any Suggestions?
Try to add NugetRestore Activity to the TFS workfolw
Note:
For Team Foundation Build 2013 on-premises and Visual Studio Team Services (formerly Team Foundation Service), the default Build Process Templates already implement the NuGet Package Restore workflow without any special configuration.
I came across a similar error for log4net nuget package and I solved it in a different way. May be this will be useful to someone some day.
The error from TFS Team Build 2015
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\
Microsoft.WebApplication.targets (182): Could not copy the file "bin\Log4net.dll"
because it was not found.
Cause
The path to the nuget package in the .csproj file for referencing the package in the project cannot be found
Resolution
Edit the .csproj file of the project that has the error.
Look for the node ItemGroupin the .csproj file
You will see the HintPath pointing to a folder, most like the folder contain the name of solution as where it will file the DLL.
Replace the HintPath with <HintPath>..\..\Assemblies\3rd party\log4net\1.2.10.0\2.0\log4net.dll</HintPath>
You nuget package library may not be log4net but a different library. A very easy way would be to be edit the .csproj file of a project in the solution that contains the same nuget package library, copy the reference of the nuget in the ItemGroup and replace in the project that has the error. The reference should start contain ...\Assemblies\3rd party\ ... instead of a physical file location on your machine

NuGet package files not being copied to project content during build

I am building an MVC4 web application with VS2012 professional with NuGet Package Manager version 2.2.31210. I have multiple projects in my solution, all sharing various packages I installed using NuGet. One of my projects is an MVC4 web application where I am using packages such as bootstrap, jquery UI, etc, all installed using NuGet.
When I clone a fresh copy of my entire solution from my repository and build my MVC4 project, the package restore feature seems to be working: it creates the packages directory under the solution direcotry and populates it will all the versions of the packages I expect to see. However, the content files do not get copied to the appropriate places in the MVC app directory. The weird thing is that it does create directories for the content, but does not copy the content files themselves.
For example, I am using the Twitter Bootstrap package which appears in the packages/Twitter.Bootstrap.2.2.2. In the MVC project a directory called bootstrap (containing css, img, and js directories) gets created in the Content directory. But, no css or js files are copied into those directories!
Does anyone have a clue what magic incantation I must utter to get the build to copy these content files from the NuGet packages directory?
This is a very common issue we are all having. I've created an MSBuild Task NugetContentRestoreTask that will do this trick for you. Run the following command in the Package Manager Console:
Install Nuget Content Restore MSBuild Targets
PM> Install-Package MSBuild.NugetContentRestore
The only thing left is to call it from your BeforeBuild Target with something like this:
Project File Targets
<Target Name="BeforeBuild">
<NugetContentRestoreTask SolutionDir="$(SolutionDir)" ProjectDir="$(ProjectDir)" />
</Target>
You can take a look at the source repo and find it on nuget.org
Additional Content Folders
This nuget only includes the default folders scripts, images, fonts, and content, it is not a recursive directory includes. For additional content subfolders - you must assign the property AdditionalFolders.
<Target Name="BeforeBuild">
<NugetContentRestoreTask SolutionDir="$(SolutionDir)" ProjectDir="$(ProjectDir)"
AdditionalFolders="less;sass;common" />
</Target>
I have found a workaround, but it is ugly. By executing the following command in the NuGet Package Manager Console: Update-Package -Reinstall all the files are indeed copied to their proper places within the Mvc project Content and Scripts directories.
Unfortunately, this is risky because you are likely to end up with the wrong versions of certain packages. For example, in my case after the command finishes executing (which takes quite a while by the way), I end up with jQuery version 1.4.4. This is way old, and I assume it must be an explicit dependency of some other package that is being updated. So it appears that the order in which the packages actually get updated by NuGet is significant (it does not appear to parse the entire dependency tree for all packages and pick only the latest versions from the union of all dependencies, which seems like it would be the preferred behavior). Rather, as the command executes I see it replacing the jQuery package several times with different versions as it works its way through all the packages and their dependencies, only to end up with a very old version.
A similar approach is the execute the Update-Package -Reinstall command explicitly for each package that is causing my problem, but this is incredibly tedious and error prone.
The NuGet Package Restore feature should yield the same result as manually executing the Install-Package or Update-Package -Reinstall command for a package, but it does not.
I don't like to have the thirdparty JavaScript files under source control either. Thats why I've followed Jeff Handley advice in http://nuget.codeplex.com/workitem/2094 to create a solution my self. I didn't go the executable way, but created a nuget solution level package which does the trick.
http://www.nuget.org/packages/Baseclass.Contrib.Nuget.GitIgnoreContent/
It's tied to git, as it automatically updates the .gitignore file.
Short description:
Ignore nuget content files in git:
Generate entries in the .gitignore file to exclude nuget content files from the source repository
Restore nuget content files before building (Automatically in VS and manually with a powershell script
I've written a blog post describing how to use it.
http://www.baseclass.ch/blog/Lists/Beitraege/Post.aspx?ID=9&mobile=0
In Visual Studio 2015 Update 1, they now support contentFiles. The caveat with this is that it only works in projects that use project.json.
In reference to the problem that you are having, there is a good blog post that explains why you see this behaviour: NuGet Package Restore Common Misconceptions.
For my projects it turned out that content files work with PackageReferences only:
Existing project with nuget references via packages.config
Installed NuGet package with content files
Build project
No content files in output directory
Conversion of packages.config to PackageReferences
Build project
Content files have been copied to output directory
IDE is Visual Studio 2017. The project is an application project which means it is in the old csproj format.