I have the following error in Jenkins ( refers to a path on the disk, each instance of below can be different and not neccasarily the same as all other instances of )
The command "tsc "C:\<path>\shared.editpage-default.ts" "C:\<path>\shared.editpage-editenabled.ts" "C:\<path>\shared.filters.ts" "C:\<path>\perfect.common.interfaces.d.ts" "C:\<path>\perfect.hide-and-seek.ts" "C:\<path>\perfect.domutils.ts" "C:\<path>\jquery.validation.d.ts" "C:\<path>\perfect.pagination.ts" "C:\<path>\perfect.sorting.ts" "C:\<path>\jquery.d.ts" "C:\<path>\perfect.langchange.ts" "C:\<path>\perfect.switchbox.ts" "C:\<path>\perfect.validation.ts"" exited with code 9009.
c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(847,9): warning MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [C:\<path>\<proj>.csproj]
Now, the issue is this. We have a section in our project file that builds our TypeScript files and creates .js files each time we save the TypeScript file. This is the section:
<Target Name="BeforeBuild">
<Message Text="Compiling TypeScript files" />
<Message Text="Executing tsc$(TypeScriptSourceMap) #(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
<Exec Command="tsc$(TypeScriptSourceMap) #(TypeScriptCompile ->'"%(fullpath)"', ' ')" IgnoreExitCode="true" />
</Target>
This all works great locally, but fails in Jenkins because the Jenkins server does not have TypeScript installed. The thing is that I don't actually need the TypeScript command to be executed on Jenkins because the generated .js files are, as I said, built and created on save anyway, and we check these in. So there are three options.
Install TypeSctipt on the build server.
Change the command in the project file so that it only carries out the <Exec Command="tsc ... if we are in the configuration is Debug.
Change my build scripts to somehow not build the TypeScript files.
Here's what I've tried.
I thought I'd try install TypeScript on the build server, but the server is an old Windows Server 2003 machine and when I tried to install TypeScript 0.8.3 on it I got the below error. So, I installed the latest windows updates on the machine and restarted and re-ran the TypeScript installation and got the same error.
As for options 2 and 3.
I think 2 would be the easiest one, though I just don't know the if statement that I must use to only build for the Debug configuration. If this is the solution please do let me know the command.
Option 3 I think is probably quite difficult.
Please do make some suggestions.
Option 2 should be easily doable. The Exec task (http://msdn.microsoft.com/en-us/library/x8zx72cd.aspx) supports the Condition parameter (http://msdn.microsoft.com/en-us/library/7szfhaft.aspx). I think what you want looks something like this:
<Exec Command="..." Condition="'$(Configuration)' == 'Debug'" />
Related
I am having trouble figuring out how to use VSTS to deploy an arbitrary directory from my build to an azure web app.
The arbitrary directory is produced during the build step and contains the webpack bundled javascript for my app. Here are the details:
I have an MVC 5 app and I just started using webpack to bundle the output of my typescript files. webpack creates a set of bundles and writes them to $(project_dir)/Scripts/bundles.
All my typescript source are in various other directories under /Scripts as well (App, Api, Lib etc). But from a VS project point of view, bundles is empty, but added to the project.
Everything works great locally. I can do a debug build and webpack-dev-server serves up the bundles. I can do a release build and webpack happily creates the bundles on disk in /Scripts/bundles. And my code happily consumes the bundles.
I have edited the project file to include:
<Content Include="Scripts\Bundles\**" />
and if I do a publish from within visual studio it all works great. But VSTS doesn't seem to recognize this part of the project
We use VSTS to do our building and releasing to azure. I can't for the life of me figure out how to get VSTS to publish this /Scripts/bundles directory.
In my project properties, I created a pre-build step that runs webpack. I know that the files are in the Scripts/bundles directory at the end of the build because the closest I have come to getting this working is to have the VSTS build a second artifact that is the zip file of that bundles directory and the files are in there.
I could solve my problem if I knew one of the following (I think):
how to get an arbitrary directory to show up in the main artifact like the normal build output - I can then use my standard release definition to push it to azure
how to publish a second artifact in a release definition?
If you can solve #2, the issue is that in building the artifact for /Scripts/bundle, it put the contents of the bundle directory in the root of the zip file, rather than having bundle as the root of the zip file. So when I unzip the file, It will have to first create /Scripts/bundle and then unzip.
I must have been entering the wrong search terms when I was first trying to figure out how to do this. Once I hit on the right search terms I found a bunch of articles that talk about how to get "extra files" into the deployment package for Azure.
Here is a good article. I basically followed it and things just worked. I added these lines to my csproj file:
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
WebpackBundles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
WebpackBundles;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
<Target Name="WebpackBundles">
<ItemGroup>
<_CustomWebPackFiles Include="Scripts\bundles\*" />
<_CustomWebPackFiles Include="Scripts\bundles\**\*" />
<FilesForPackagingFromProject Include="%(_CustomWebPackFiles.Identity)">
<DestinationRelativePath>Scripts\bundles\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
The PropertyGroup was already there. I just inserted the WebpackBundles; call into those two elements and then defined the WebpackBundles target.
And I ended up removing the
<Content Include="Scripts\Bundles\**" />
line and replaced it with the new Target that the article suggests. I am running webpack as a pre-build step only on the release build. I am using webpack-dev-server for the debug build locally. The only change I had to make to our VSTS build was to add two npm steps:
npm install
npm install webpack -g
this allowed the pre-build step to find the webpack executable and run it.
there was no change to the VSTS release definition because the webpack bundles got put into the deployment zip file in the right location.
I'm developing a front-end package and this is my environment:
IDE: Visual Studio (I'm on Windows and we use TypeScript)
Package manager: NPM
Task runner: Gulp
CI: TeamCity
My problem is that I'm trying to avoid installing node and Gulp globally on my build servers (mainly because I don't want to bother managing this - installing, updating, synchronizing, etc.).
So I found a NuGet package (https://www.nuget.org/packages/Npm.js/) which allowed me to restore all the packages without having node installed on the machine. But then the problem was that the local Gulp I installed assumes there's a node.exe right next to it or in the machine's path:
#IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\gulp\bin\gulp.js" %*
) ELSE (
#SETLOCAL
#SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\gulp\bin\gulp.js" %*
)
Now obviously this won't work since I don't have node installed on the build machine and there's no local node installation inside node_modules.
So is there any way to avoid installing my build tools globally on each build server? Or were Node and Gulp intended to be installed everywhere? How should then updates be maintained? It's not like a Visual Studio release which comes out once every few months... Or do you just ignore frequent releases of the build tools?
I could also add the NuGet package to the path but that (the path where node.exe is located) depends on the version of the NuGet package and requires more maintenance whenever updating it. So I prefer not going this way either...
It's not optimal but here's what I ended up doing: I used a NuGet package for setting environment variables in MSBuild and created the following build configuration:
<Target Name="GulpBuild">
<SetEnvVariable Name="path" Value="%path%;..\packages\Node.js.5.3.0" />
<Exec Command="node_modules/.bin/gulp" />
</Target>
Now when I build the solution in VS (CTRL+Shift+B) it adds the node location to the path and then calls gulp. Of course I guess I could have just written the gulp command myself including the node path.
In any case, this is of course not optimal because I need to manually update the location if I update the Node.js version, but I couldn't find any better solution.
At least the path configuration is defined inside the repository and does not depend on any machine configuration.
Late here, but I think you can setup your gulp project to run with the gulp installed to node_modules. For example, on npm start you can use the path the binary.
In short, can you change the project to not use the global gulp? It might be work looking int.
In the Visual Studio 2012 Build menu, there's a Publish command. In this you can establish profiles which are saved as .pubxml files in the Properties folder of the Project. I have one such profile that's a simple file copy operation - it just compiles the site and dumps it to a folder.
How can I use msbuild at the command line to publish a compiled web application to a folder?
What I've tried
I've tried the example from this question:
After Publish event in Visual Studio
And the changes and examples given here:
http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild
The latter seems to get closest, but it causes every library Project the .csproj I'm attempting to publish from to throw an error:
Project "MainProj.csproj" (1) is building "ReferencedProj.csproj" (2) on node 1 (default targets).
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(609,5): error : The OutputPath property is not set for project 'ReferencedProj.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Staging' Platform='AnyCPU'. You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project. [ReferencedProj.csproj]
Done Building Project "ReferencedProj.csproj" (default targets) -- FAILED.
This approach is very similar to what's suggested in this answer:
https://stackoverflow.com/a/7077178/176877
The crucial difference may be that I'm in Visual Studio 2012, rather than VS2008 or 2010.
Old question, but in case this helps anyone, this simple, stripped back approach worked fine for me:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
...
<BuildDependsOn>
$(BuildDependsOn);
PublishOtherProject;
</BuildDependsOn>
</PropertyGroup>
<Target Name="PublishOtherProject">
<MSBuild Projects="pathtomyproject.csproj" Properties="DeployOnBuild=true;PublishProfile=nameOfPublishProfile" />
</Target>
The key line being:
<MSBuild Projects="pathtomyproject.csproj" Properties="DeployOnBuild=true;PublishProfile=nameOfPublishProfile" />
I have installed the latest version of TypeScript and also the latest version of Web Essentials. I created a new TypeScript project in VS2012.
If have a utils.ts:
moduls utils
{
export function getNumber() {
return 4;
}
}
And a app.ts:
/// <reference path="utils.ts" />
alert(utils.getNumber().toString());
The JavaScript files are both compiled seperatly. But to get app.js to work properly, the compiled source code of utils.ts has obviously to be included.
It does work when I run tsc app.ts -out app.js in my console, but I do not want to run it everytime manually.
Why cannot Web Essentials do the for me?
I have Web Essentials installed as I love the side by side editing, but I use the TypeScript compiler from within the project file to compile a single output.
The details are here: http://www.stevefenton.co.uk/Content/Blog/Date/201301/Blog/Getting-The-Right-Set-Up-For-TypeScript/
But the chunk of code for your project file is:
<Target Name="BeforeBuild">
<Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\TypeScript\$(TypeScriptVersion)\tsc" --out final.js #(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
</Target>
You'll probably find this is mostly already there in your project file and you just need to add the --out flag.
I'm working with VS2012 express for Web/TypeScript0.9.0.1 and the above didn't work. In case anyone else has this problem with that setup, I did get a similar workaround going where
in Project Properties -> Build Events -> Pre-build event command line I added: "C:\Program Files (x86)\Microsoft SDKs\TypeScript\tsc.exe" --target ES5 $(ProjectDir)app.ts -out $(ProjectDir)Final.js
Modified default.htm to load Final.js instead of app.js
I've added file1.ts and I can see there's a dependent to it - namely file1.js.
I notice that any changes I made to file1.ts - file1.js doesn't get automatically re-generated.
The only workaround I have at the moment is by calling tsc.exe - as part of pre-build event.
My question is - are there any better workaround or maybe a setting somewhere I might've missed ?
Install the Web Essentials 2012 extension in Visual Studio 2012.
It will re-generate the .js file on every save of the .ts file.
http://visualstudiogallery.msdn.microsoft.com/07d54d12-7133-4e15-becb-6f451ea3bea6
You have to add a BeforeBuild target to your ASP.NET application's CSPROJ:
<Target Name="BeforeBuild">
<Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc" #(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
</Target>
tip: edit your csproj file with notepad.
Support for typescript has been removed from Web Essentials 2012 v3
you now need to download typescript support directly from microsoft:
http://www.microsoft.com/en-us/download/details.aspx?id=34790
In Visual Studio you need to invoke the build process for your files to be generated. The playground does not use the same build system, and it triggers the compilation once the source changes, so this is why you are seeing the difference in behavior.
plug
You can use Install-Package TypeScript.Compile to add a afterbuild target that compiles all TypeScript files included in your project.