I have an ASP.NET MVC 5.0 application, and I have introduced a package.json file to manage JavaScript packages in my project (I reference the node_modules path in my BundleConfig.cs to pull in the packages).
When I pull down a new version of the project and build it, Visual Studio seems to automatically retrieve the NPM packages (I'm assuming Visual Studio 2017 has built in support for this).
However, when I publish my application, the node_modules folder does not get generated. I added the following build target to my web .csproj file in the hope this would resolve the dependencies on publishing:
<Target Name="PrepublishScript" AfterTargets="PrepareForPublish">
<Exec Command="npm install"/>
</Target>
However, the command doesn't appear to be executed.
The npm command is definitely part of my path (i.e. when I open a command window and type npm it executes).
Any ideas why this isn't working?
Is this even a reasonable approach?
This worked for me:
<Target Name="CustomPostPublishActions" AfterTargets="GatherAllFilesToPublish">
<Exec Command="npm install" WorkingDirectory="$(PublishUrl)"></Exec>
</Target>
$(PublishUrl) appears to be a built-in variable which I used to ensure that the command was executed in the folder where my published files are being output to.
One caveat is that this doesn't really help when it comes to one-click publish with IIS Web Deploy, I'm not sure what I would need to do for that.
Related
Trying to build to .NET-Core Project from TFS, the build is failing because the following command`s not working, failing to copy built files to output folder. The command is working fine for a .Net Framework project, not working only for .Net Core Project. Kindly check.
It works fine with basic command:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin>MSBuild.exe "C:\TFSFolder\Builds\GUID\DotnetCoreProject.sln" /p:OutDir="C:\TFSFolder\Builds\39\b\DotnetCoreProject\\"
Non-working Command:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin>MSBuild.exe "C:\TFSFolder\Builds\GUID\DotnetCoreProject.sln" /nologo /nr:false /t:"Clean" /dl:CentralLogger,"C:\TFSFolder\Builds\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.126.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=2c81e6a8-374d-4a65-91ba-418b04505e77|SolutionDir=C:\TFSFolder\Builds\GUID\"*ForwardingLogger,"C:\TFSFolder\Builds\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.126.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:OutDir="C:\TFSFolder\Builds\39\b\DotnetCoreProject\\" /t:Restore /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="15.0" /p:_MSDeployUserAgent="TFS_fa1cf861-541e-47b2-b0f3-8c684de5500a_build_22138_1486294"
It just need to copy built files to the output folder path mentioned. I could only guess that the dll mentioned isnt supported, kindly check and help.
It looks like you are only restoring and cleaning the project because you specify /t:Clean and /t:Restore.
Use -restore -t:Rebuild instead.
Also note that you normally don't want the output directory contents of a .NET Core project for deployment but rather its publish output. For this use the Publish target on the project instead:
-restore -t:Publish theproject.csproj -p:PublishDir=artifact\location
When I build .NET Standard 2.0 Library on Jenkins build server
C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error : Assets file 'C:\Jenkins\workspace\<Project>\Sources\Library\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. [C:\Jenkins\workspace\<Project>\Sources\Library\Library.csproj]
I got an error above in build log.
I searched about error and I found solution
However, when running:
dotnet restore <Solution Name>
the solution does not help me out when I clean my workspace before build starts.
Therefore, I insert command before MSBuild but I failed with
C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error : Package Microsoft.CodeAnalysis.CSharp.Workspaces, version 2.8.0 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [C:\Jenkins\workspace\<Project>\Sources\Web\Web.csproj]
According to Solution reference, maybe upgrade Nuget Package Installer could help me out. But I do not know how can I upgrade Nuget Package Installer by command line...
I had the same problem, getting the same error:
error : Package <package> was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [<path>]
I was able to solve it using MSBuild /t:restore instead of dotnet restore.
See: https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-target
UPDATE: It's worth mentioning that problems in Jenkins are discussed in depth in this other answer.
The hint by #Mat didn't work for me: the /t:restore is currently not able to restore nuget packages for projects using package.config, as I mention here. What worked for me is the following:
call "%PROGRAMFILES(X86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
nuget restore CodeBinder.sln
MSBuild Solution.sln /p:Configuration=Release /p:Platform="Any CPU" /t:build /restore
pause
It basically requires to download the nuget CLI from official site[1], Windows x86 Commandline section. The switch /restore , as pointed here, fixed the partially completed Nuget restore error, similarly to MSBuild /t:restore, but it can be done in conjunction with /t:build.
[1] https://www.nuget.org/downloads
Visual Studio 2015 Enterprise
Nuget.exe 3.4.4.1321
Project: Windows Forms Class Library
OK I have project.json file setup in my solution and this builds fine. I have NO IDEA how msbuild finds the packages project.json asks for, but that's fine.
I check the files into TFS 2012 (ya I know, our company won't upgrade yet)
TFS fails to build. Says "type cannot be found..."
How on earth do you DEBUG these sorts of issues when you have NO IDEA where MSBuild even LOOKS for packages?
I can GUESS where MS Build may be looking, but how can I confirm this?
csproj hintpaths had their drawbacks, but at least you KNEW where msbuild would look for your package
with Project.Json I have no idea where msbuild is looking!
The package IS there on the build server, right where I expect it to be. How to tell msbuild.exe where to look for packages?
According to your error message, it seems that something wrong with the reference using. For trouble shooting your issue, please try the following.
Please use Package.config for your project to install packages in TFS build. Check if it works to make sure your assemblies and packages are fine.
If Package.config doesn't work. Please provide the detail steps for me to reproduce your issue.
If package.config works but project.json doesn't works. Look at this document: Converting a csproj from package.config to project.json
To debug a build: https://msdn.microsoft.com/en-us/library/jj635150.aspx?f=255&MSPPError=-2147217396
Note: To always use the latest version of the package available, you could add the following to Nuget.config file. So it will get the latest version when you use packages.config. The Nuget.config file is at: C:\Users\UserName\AppData\Roaming\NuGet
(nuget spec dependencies, get latest version?)
<configuration>
<config>
<add key="dependencyversion" value="Highest" />
</config>
</configuration>
project.lock.json will report the resolution path for nuget packages.
This will appear at the VERY BOTTOM of the project.lock.json file:
sample:
"packageFolders": {
"c:\\nuget_packages": {}
Adding this key in nuget.config tells nuget where to restore packages:
<config>
<add key="globalPackagesFolder" value="c:\nuget_packages" />
</config>
This ONLY works for nuget 3+ with project.json file, not with packages.config
I am learning angular 2 with Typescript.
I am using following resource.
QuickStart with Angular 2
Now from there and other examples i found that they telling to create package.json file that lists all dependencies for project.
I think creating this package.json file and listing all dependency packages this kind of structure is followed in .NetCore Project.
In MVC 4 or 5 we have packages.config file which lists although packages that we are going to use.
I am not saying we can not use package.json file when we have package.config file.
But is there any simple way to integrate Angular 2 with typescript in MVC Webapplication project using NUGet Packages and get started?
If not available please let me know how can i setup Angular 2 with type script in ASP.Net MVC 4 or 5?
As you said, in ASP.NET MVC application you have a package.config file. This file holds the information about NuGet packages you've installed in your app. This file is related to the server-side packages.
package.json file is related to a front-end part of your app. It also holds list of packages that you've installed in your app. This time npm packages. It also holds information about your app and more. You can read more about it here.
You can't mix those files and you don't want to. Firstly, those files have different format (XML and JSON). In addition, as I said before, they hold information about different parts of your application. Lastly, and this is my personal opinion, when you create application with rich UI and use Angular2, it'd be better to split the parts of your app into 2 different projects. One of them with Web APIs and the second with the UI part only. With such structure, you will no need for packages.config in UI project and no need for package.json in Web API project.
For you last question, you can start with here. You also can take a look on this sample app.
In order to run Angular 2 in an ASP.NET MVC 4.5 (VS 2015):
1) install Node.js (at least 4.4.x), npm (at least 3.x.x) and TypeScript for Visual Studio 2015 (VS -> Tools -> Extensions and Updates -> Online). You may check your version of node and npm by running the following in the terminal: "node -v" and "npm -v".
2) copy the QuickStart files (everything what quickstart-master constains, not the folder itself) into your project (to the folder containing the .csproj file) - you can download the QuickStart files from: https://github.com/angular/quickstart
3) In the Solution Explorer click "show all files" (probably the third icon from the right, just above the search bar). Select the following files/folders and include them in the project:
app folder (answer No if asked to search for TypeScript Typings)
styles.css
index.html
package.json
tsconfig.json
typings.json
4) In Visual Studio, right click on "package.json" and select "Restore Packages" - this will install all of the packages defined in the package.json into your project.
The result of this operation is the same as running "npm install" in your project location from the terminal.
Probably there'll be some warnings in the Output window - ignore them. A new folder called "node_modules" will be generated (you need to refresh the Solution Explorer to be able to see it) - advice is not to include this folder in the project.
5) In the tsconfig.json file, next to "compilerOptions" add the following:
"compileOnSave": true
as shown below
{
"compilerOptions": {
...
},
"compileOnSave": true
}
Restart Visual Studio.
6) In Visual Studio, right click on "index.html" and click "Set as Start Page".
As a reference, here's the official documentation for running Angular
2 (quickstart) in ASP.NET 4.x (Visual Studio 2015):
https://angular.io/docs/ts/latest/cookbook/visual-studio-2015.html
Also check out the link which includes steps to run.
You need to include package.json (Angular 2 gets installed using NPM)
Run NPM install
Run the GULP tasks
Run F5 to see results.
https://github.com/mithunvp/ng2Mvc5Demo
As its already accepted still it will be alternate way to get started
If You want to install Angular4 on nuget package manager console you can use Install-Package Angular4 -Version 1.1.0 and follow these steps:
Angular 4
*********
Prerequisites
`````````````
1. Download and Install Node js
2. Install Visual studio 2015 update 3 or above
3. Download and Install TypeScript 2.6.1 for Visual Studio 2015 (https://www.typescriptlang.org/#download-links)
Follow the steps to install package.
````````````````````````````````````
1. Create an new project with empty template and include dependencies for MVC and WebApi to the project
2. Install the package using command 'Install-Package Angular4 -Version 1.1.0'
Follow the steps after package installation
```````````````````````````````````````````
1. Open Node.js Command Prompt
2. Navigate to project location(use commands such as pushd,cd etc)
3. Run the command 'npm install'
I found a salesforce plugin for intellij IDEA (link), and now trying to install it. The problem is, i've never done this before. So according to instruction:
How to build and install
Until the plugin is released into the IntelliJ plugins repository, you
can following these instructions for manually building and installing
the plugin from GitHub:
Update the ANT script salesforce-plugin-xml with the location of your IntelliJ IDEA install
<!--property name="idea.path" value="C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.0.2"/-->
<property name="idea.path" value="/Applications/IntelliJ IDEA 13.app"/>
Execute the 'package' target of the ANT script - this will create a salesforce-plugin-#.#.zip file in the out directory
Go into IntelliJ IDEA settings under Plugins and select "Install plugin from disk". Select the zip file and click Ok.
I downloaded a project from github, added path to idea to salesforce-plugin.xml. Then i realized that i don't have an ant to build it. I installed homebrew, installed ant, checked the version (ant appeared, ok).
Then i stuck. I tried different combinations, how to package the plugin, The last attempt is when i changed salesforce-plugin.xml to build.xml and wrote in terminal:
ant package build.xml
got:
Buildfile: /Users/cooler/Downloads/salesforce-plugin-master/build.xml
BUILD FAILED
/Users/cooler/Downloads/salesforce-plugin-master/build.xml:36: taskdef
class com.intellij.ant.Javac2 cannot be found using the classloader
AntClassLoader[]
Can you help me please to do this in right way!?
BTW, i use Mavericks
On a Mac, you need to add /Contents to the root path of the IDEA installation. For example:
<property name="idea.path" value="/Applications/IntelliJ IDEA 14.app/Contents"/>
When generating ant build scripts:
build -> generate ant build
-> check "use current idea instance for idea.home property"
Re-generate the ant build scripts. Now the build should work propertly.