4

We use MSBuild on our CI server to compile our WebApp, however the build omits the JavaScript files built by TypeScript from the output of the build.

I would expect the output to contain the JavaScript and not the Typescript, however neither are in the output at the expected locations.

How can I include the JavaScript files without having to have them all in my solution? The TypeScript team seems to think this is bad, but I would rather not have duplicates of all the files in my solution either.

Chris Barr
  • 29,851
  • 23
  • 95
  • 135
Gent
  • 2,675
  • 1
  • 24
  • 34
  • Hi @Gent, I was wondering if you got it to work? Please let me know if you still have a problem with this. – Thomas D Oct 02 '14 at 07:36
  • @MrMathos I got it figured out, however the typescript installation was present on the build server so it ended up being a different issue than detailed in your answer. Thanks for your time and help. – Gent Oct 03 '14 at 18:51
  • No problem, glad you found it! – Thomas D Oct 07 '14 at 12:33

4 Answers4

7

The problem was due to using MSBuild instead of the "Publish" on the build server it seems. I added an AfterBuild target to content include all of the JS files to the build output.

<Target Name="AfterBuild">
   <ItemGroup>
      <Content Include="**\*.js" />
   </ItemGroup>
</Target>

Although this is not ideal, it allows the js files not to show in the solution when using visual studio and the files end up in the build output.

Gent
  • 2,675
  • 1
  • 24
  • 34
  • let me ask you - when you added this it actually puts the files on the target server? I'm in a similar situation where I got my whole deal working using publish locally, but when I actually ran the same .csproj setup on the actual build server by queueing a build, it didn't work. – NullHypothesis Oct 04 '14 at 01:55
  • Yep, it works through msbuild on jenkins and via octopus deploy as well, as long as its added to the csproj itself – Gent Oct 04 '14 at 22:37
  • This is so weird, why would mine not copy the files to the target server? It doesn't put them in the _publishedwebsites folder, nor the target server itself. I basically just used what you have above. Was there anything else? – NullHypothesis Oct 05 '14 at 18:52
  • Have you verified that the js files exist in place after build? For example if you had "Scripts/SomeLibrary.ts" you find a "Scripts/SomeLibrary.js" – Gent Oct 05 '14 at 23:56
5

I tried many solutions from the web including the <Content Include="**\*.js" />, but nothing worked. I'm using MSBuild on my local dev box and typescript is installed and targets available in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\TypeScript.

It turns out my "old" MSBuild runner for web app csproj files is obsolete. I was doing this:

MSBuild.exe my.csproj /Target:ResolveReferences;_CopyWebApplication /property:WebProjectOutputDir=myfolder;OutDir=myfolder\bin;Configuration=Debug 

but thanks to this post I need to use UseWPP_CopyWebApplication instead of the legacy _CopyWebApplication:

MSBuild.exe /t:Rebuild "/p:WebProjectOutputDir=myfolder;OutDir=myfolder\bin;Configuration=Debug;UseWPP_CopyWebApplication=True;PipelineDependsOnBuild=False" my.csproj

Now without any editing of the csproj file, all my TypeScript is included!

Community
  • 1
  • 1
thinkOfaNumber
  • 2,581
  • 3
  • 27
  • 46
  • Thank you! This should be marked as the answer. The answer you've linked to investigated and found the root of the problem coming from a poor decision by Microsoft in their Publish task target file. – Simon Brangwin May 19 '15 at 23:36
0

TypeScript is probably not installed on your build server. To install it, copy your TypeScript folder from c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\ to the same folder on your build server (where v12 is the version of your Visual Studio).

The Visual Studio version on your build server can be different however. In my situation, the version on my development machine is v12, while the build server uses v11. I found that out by adding the following to the [WebProjectName].csproj file:

<Target Name="PrintVisualStudioInfo">
    <Message Text="VisualStudioVersion: '$(VisualStudioVersion)'" Importance="High" />
</Target>
<PropertyGroup>
    <CompileDependsOn>
        PrintVisualStudioInfo;
        $(CompileDependsOn)
    </CompileDependsOn>
</PropertyGroup>

Be sure you put it after the last <Import /> element. Now when you look at the output of your build on the build server, you should see 'VisualStudioVersion: xx' somewhere.

Copy the TypeScript folder to the correct version folder on the build server.

Thomas D
  • 412
  • 4
  • 10
0

Just adding in case it helps people.
We had this issue recently and it was fixed by adding /p:VisualStudioVersion=12.0 to the BAT file :

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe FullBuild.proj /p:VisualStudioVersion=12.0 /t:createRelease /p:ReleaseNumber=5.22.0
Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
Eoin O
  • 83
  • 1
  • 4