Correct way to deal with downloaded d.ts files from DefinitelyTyped when installed via npm - asp.net-mvc

Visual Studio 2017 Enterprise
ASP.NET MVC Application
TypeScript 2.5 SDK
Source control is in TFS
I am using Microsofts built in property editor instead of a custom tsconfig.config file:
To allow an easy workflow I am using Mad's Kristensen's Package Installer to do my NPM installations of Definitively Typed TypeScript definitions within my MVC web project.
Ultimately this ends up creating node_modules in a folder under the solution path:
While I could use this SO post to do a GLOBAL install using -g --prefix so that I could place this into a folder of my choosing say:
MVCProjectFolder\TypeScript\Npm\Modules
I have some concerns or at least a request for a better way.
So my questions are:
Is there a different way to changing the node_modules folder from within Visual Studio without specifying -g -prefix
What is the best approach to bundle all the TS generated JavaScript in the project? (The TypeScript Build property option "Compile JavaScript output into file" appears to have no effect)
Do I only need to include the d.ts tiles in TFS so that the following will keep on working when synced?
--
/// <reference path="../../node_modules/#types/jquery/index.d.ts" />
/// <reference path="../../node_modules/#types/handlebars/index.d.ts" />

Answer your TFS part, you don't need to check in node_modules folder to TFS. When you want to build your project in TFS, add a nmp task in your build definition:
https://learn.microsoft.com/en-us/vsts/build-release/tasks/package/npm

Related

Nuget Packager the default XML namespace of the project must be the MSBuild XML namespace in TFS 2017

I changed the project type I am packaging from .net framework v4.6 to .net standard 2.0, now the build definition is failing in Nuget packager step and I am getting this error message.
[error]The default XML namespace of the project must be the MSBuild
XML namespace. If the project is authored in the MSBuild 2003 format,
please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
to the element. If the project has been authored in the old
1.0 or 1.2 format, please convert it to MSBuild 2003 format.
After researching about this error I understand that the NuGet packer step doesn't work on SDK-based csproj formats.
What is the best alternative available? I found the same issue here, but I can not find the command pack within the available commands.
While the pack command does not appear in the dropdown, you can enter it manually into the field.
This is how I resolved this issue:
1- Add package metadata to .csproj file.
2- Go to project properties -> package and check "Generate NuGet package on build".
3- In Build definition add the following tasks:
a- NuGet Restore:
Set path to solution.
Select Feeds in my NuGet.config as Feeds to use.
Set path to Nuget.config (Usually project root "src\nuget.config").
b- Visual Studio Build:
Set path to solution.
Platform: something like $(BuildPlatform).
Configuration: something like $(BuildConfiguration).
c- Copy and Publish Build Artifacts:
In contents enter *.nupkg.
Set Copy Root, Artifact name, and Artifact type.

Include files to build generated by angular-cli before build in asp.net mvc

I am struggling with a issue for files generated by nodejs needed to be included in build. It works well in local development but when i want to publish it then it won't include files fron dist folder to build and app will not have a dist folder. Can any one help on this?
Note:- files are created each time has different name so i cannot select and include them. I am using visual studio 2017. I hope i could explain the issue or let me know i can try better. Thanks in advance
You need to put your static files under the wwwroot folder to make them accessible on the production server.
To include those files for publishing, a simplest option would be to add them to wwwroot before a publishing starts, otherwise they will be ignored.
Another option would be to tell MSBuild to include the files explicitly.
You can find an example of how to customize the project file at <Target Name="NgBuildAndAddToPublishOutput" AfterTargets="ComputeFilesToPublish">.
You could build for production with Angular CLI with --output-hashing=none like so:
ng build --prod --output-hashing=none
And then include the generated js-files into your project-file (csproj). Then use a Script-bundle in BundleConfig.cs with BundleTable.EnableOptimizations = true; to generate the hashes for you by ASP.NET instead of Angular-cli.

How to include config transform files in web application filesystem publish output

I've been pulling my hair out on this for a while now. I'm trying to implement a continuous integration and deployment pipeline using TeamCity and Octopus Deploy. I am 99% there, except for one problem. I am using the standard msbuild runner of teamcity, configured to use the version 12 of msbuild.
I need to include the web.config transforms in the published output so they can be packaged into a nuget package for octopus deploy. I do not want the transforms to be applied by msbuild.
I am not using Octopack to create packages. I'm using the built-in teamcity nuget packager. So I'm publishing the website to a filesystem folder and then creating the package from the files in this folder. However, no matter what I do I cannot get msbuild to include the web.config transform files in the publish (I am using Octopus Deploy to perform the transforms, so I don't want msbuild to perform them).
I have verified that all the transform files (Web.Release.config, etc..) are marked as "Content". I have NOT marked them to copy always, because doing this copies them to the bin folder, not the root folder where they belong.
I have removed the /p:Configuration= property from the msbuild command line as I've read that is required for transforms to be applied. my parameters to msbuild look like this:
/p:DeployOnBuild=true /p:PublishProfile=Deployment
There is nothing in the publish profile that seems to relate to transforms. The publish profile contains the filesystem location to publish to.
Any suggestions here?
Note: I've given up and found a different solution, but I'm leaving this open in case anyone has any input.
You could create a custom .nuspec file and reference the files that you want to include from there.
My suggestion would be to have the .nuspec file in the same directory as the web.config / web.release.config files, and make the paths relative from there.
So if you publish to a directory called /output you could use rules like this
<files>
<file src="*.config" target="\" />
<file src="publish\*.*" target="\" />
</files>
So nuget pack nuspecPath would become the way to pack the project
NuSpec Reference
Hope this helps

How to change script or style files location from nuget?

I have a MVC project and I am using jquery, bootstrap and some other files from nuget. In mvc by default all of scripts files is in Scripts and all of css files is in Content as you know. I moved all scripts and css files to Content/css , Content/js , after that i got a problem because the files are going to the default location (js => Scripts, css=> Content) when i update my nuget packages.
So how can i solve this problem ? Is it possible ?
In NuGet it is not possible to control where content files get installed to. The author of the NuGet package decides entirely what path to use for content files.
Instead of using NuGet for content files, I recommend using Bower, which is based on npm (the Node Package Manager).
With Bower you can control where files get installed to. Check out this SO post on the subject (especially the second answer): How to change bower's default components folder?
More info on Bower:
Getting started with Bower: http://blog.teamtreehouse.com/getting-started-bower
Bower support in Visual Studio: http://www.hanselman.com/blog/IntroducingGulpGruntBowerAndNpmSupportForVisualStudio.aspx

NuGet Package Restore is not restoring packages on build

I am moving our source code from Vault to TFS, not bothering with the migration or anything, just pulling a get latest in vault and adding it to TFS.
The solution has got several projects, and each one has at least one NuGet package. I am trying to get Package Restore working again. It worked in Vault (but not the way it was supposed to). I was under a bit of a deadline, and it did not work at first, so I added a Pre-Build event to run nuget.exe against the packages.config for each project.
TFS build service complains about that, so I am trying to get it working "right".
I have set the option in Visual Studio Tools menu.
I have installed NuGetEnablePackageRestore and run the fix.
I have verified that the packages directory is is source control, but is empty.
I have verified that the project files each include the following:
<RestorePackages>true</RestorePackages>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
Building with Diagnostic level verbosity reveals that each project evaluates those properties, but the RestoreCommand in nuget.targets is never executed.
Any thoughts?
I have attempted to implement the solutions from these links:
nuget - package restore not working
NuGet Package Restore Not Working - I did post a question/comment on there asking for clarification...
http://nuget.codeplex.com/workitem/1879
Edit
Additionally, I have found that the RestoreCommand property is being evaluated during build. Diagnostic Verbosity shows:
RestoreCommand = (set EnableNuGetPackageRestore=true) && "C:\Source\Kiersted Direct And Related\Direct\Kiersted\.nuget\nuget.exe" install "packages.config" -source "#(PackageSource)" -o "C:\Source\Kiersted Direct And Related\Direct\Kiersted\packages"
I figured it out, and I found the answer here: MSBuild not running BuildDependsOn tasks from an imported project
The problem (after looking through the Diagnostic verbosity build output) was that the BuildDependsOn setting was getting un-set. My project files each had the import statement
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
but that statement was at the beginning of the XML tree. Apparently the import for Microsoft.CSharp.targets can interfere with that import and thus the BuildDependsOn.
My solution was to move the nuget.targets import to below the Microsoft.CSharp.targets import. Now everything builds beautifully.
This answer needs to be considered with the others. In my case, Visual Studio decided not to add the packages.config automatically into Source Control. Hence the file did not make it's way through to the build server for consideration during Nuget restore.

Resources