Visual Studio .Net Core project uses the Typescript v1.8 compiler instead of v2.0 - visual-studio

I'm using Visual Studio 2015 Pro, Update 3.
My question is how to instruct VS to use the version of the typescript compiler that I want it to use.
VS is refusing to use the Typescript 2.0 compiler, rather is using 1.8. I have installed, via Nuget in VS, Microsoft.Typescript.Compiler v2.0.3 and Microsoft.Typescript.MsBuild v2.0.3, to no avail.
Looking at the detailed output from MSBuild, I see the following:
Target "PreComputeCompileTypeScriptWithTSConfig" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets" from project "C:\Users[...].xproj" (target "CompileTypeScriptWithTSConfig" depends on it):
Using "VsTsc" task from assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\TypeScript.tasks.dll".
Task "VsTsc"
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe --project "C:\Users[...]\tsconfig.json"
Done executing task "VsTsc".
Done building target "PreComputeCompileTypeScriptWithTSConfig" in project "[...].xproj".
So it appears that VS is using the tsc.exe from the Microsoft SDK.
Anyone know how to instruct VS to use the version of tsc that I want it to use?

#starain I really appreciate your efforts.
Unfortunately your suggestion still doesn't work for me. MSBuild/VS does not use the environment path to find tsc. If it were, it would already be finding the correct version. The correct path (to 2.0.3) is already in the environment, and the incorrect path (to 1.8) is not.
I hadn't seen the link you provided to the issue with nuget. This problem does at least appear to be an issue with the nuget installation.
Aided by setting the MSBuild output to "diagnostic" I have managed to figure out a work-around on my own.
In the .xproj file inside <PropertyGroup Label="Globals"> I inserted the following:
<TypeScriptToolsVersion>2.0.3</TypeScriptToolsVersion>
<TscToolPath>C:\Users\[me]\.nuget\packages\Microsoft.TypeScript.MSBuild\2.0.3\tools\tsc</TscToolPath>
So far, it works beautifully except for one thing: Intellisense appears to still be using 1.8. I will leave that for a separate issue.
This solution could easily, of course, present a problem each time I want to update tsc. But for now it's a lot better than nothing.

You need to remove corresponding imported project from your project file.
Right click your project in VS=>Unload project
Right click your project again in VS=>Edit XXX.csproj
Remove this code:
Microsoft.TypeScript.Default.props:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />
Microsoft.TypeScript.targets:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
(Optional) If this code isn’t included in your project file, please add it (related to the code of Step 3)
:
<Import Project="..\packages\Microsoft.TypeScript.MSBuild.2.0.3\build\Microsoft.TypeScript.MSBuild.props" Condition="Exists('..\packages\Microsoft.TypeScript.MSBuild.2.0.3\build\Microsoft.TypeScript.MSBuild.props')" />
<Import Project="..\packages\Microsoft.TypeScript.MSBuild.2.0.3\build\Microsoft.TypeScript.MSBuild.targets" Condition="Exists('..\packages\Microsoft.TypeScript.MSBuild.2.0.3\build\Microsoft.TypeScript.MSBuild.targets')" />
For .net core application, it has issue with that nuget package, the typescript reference in ASP.NET Core projects is through the Microsoft.DotNet.Web.targets. So, it won't work. You can check this link (paulvanbrenk's reply).
To use higher version of typescript compiler, you can install Typescript 2.0 and change environment variable path value to corresponding folder (C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.0)

Related

msbuild: Check if Import was successful

I installed the MSBuild Community tasks to have the "Zip" task available. Everything works fine with the following code:
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
On machines where the Community Tasks aren't installed yet, Visual Studio (Enterprise 2017) entirely refuses to load the .csproj file containting the above Import statement.
Since the zip-related part is not an important step in the build process, I tried to make the .csproj also load on machines where the Community tasks are not yet installed, have msbuild issue a warning and build the zip-related targets using a condition. So I tried:
<PropertyGroup>
<MSBuildCommunityTargets>$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets</MSBuildCommunityTargets>
</PropertyGroup>
<Import Project="$(MSBuildCommunityTargets)" Condition="Exists($(MSBuildCommunityTargets))" />
Here the Community Tasks targets file cannot be found. The expanded $(MSBuildExtensionsPath) path points to an MSBuild folder below the VS installation folder while the Community Tasks install into an MSBuild folder directly below "Program Files (x86)". I suspect the Import statement does some compatibility search magic when expanding the $(MSBuildExtensionsPath) variable while this magic is not applied in simple property variable expansions.
Is there any proper way to check the presence of some installed third-party MSBuild tasks/targets?
Thank you.
Is there any proper way to check the presence of some installed third-party MSBuild tasks/targets?
Your Visual Studio version must be 2017. That because the expanded $(MSBuildExtensionsPath) path points to an MSBuild installation folder. The default value for Visual Studio 2015 and before is: C:\Program Files (x86)\MSBuild,
However, it was changed to C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild for Visual Studio 2017. And the installation path of MSBuild.Community.Tasks.msi is still C:\Program Files (x86)\MSBuild.
So when you use $(MSBuildExtensionsPath) to specify the path of Community Tasks in Visual Studio 2017, you will get the error "the Community Tasks targets file cannot be found".
To resolve this issue, we could not use the variable $(MSBuildExtensionsPath) in Visual Studio 2017 before the author updates this MSI file. As a workaround, you could use the absolute path:
<PropertyGroup>
<MSBuildCommunityTargets>C:\Program Files (x86)\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets</MSBuildCommunityTargets>
</PropertyGroup>
<Import Project="$(MSBuildCommunityTargets)" Condition="Exists($(MSBuildCommunityTargets))" />
Or use $(MSBuildProgramFiles32) instead of $(MSBuildExtensionsPath):
<PropertyGroup>
<MSBuildCommunityTargets>$(MSBuildProgramFiles32)\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets</MSBuildCommunityTargets>
</PropertyGroup>
Alternatively, you can install the Community Tasks by NuGet package. Because The MSBuild Community Tasks library is also available on nuget.org via package name MSBuildTasks. To install MSBuildTasks, run the following command in the Package Manager Console:
Install-Package MSBuildTasks
After install this package, you can find below import in the project file:
<Import Project="..\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets" Condition="Exists('..\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets')" />
In this case, you do not need to modify the project file any more, and it will not be bound by the variable $(MSBuildExtensionsPath). This is what we recommend.
Is there any proper way to check the presence of some installed third-party MSBuild tasks/targets?
Can't you use the condition? Has worked for me over the years
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" Condition="Exists('$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets')" />

Can not configure which Typescript compiler to use in VS 2015

I am installing Microsoft.TypeScript.MsBuild 2.0.3 NuGet package. This comes with the appropriate tsc.exe in its tools subfolder.
After installing the nuget package my .csproj file contains the line:
<Import Project="..\..\lib\Microsoft.TypeScript.MSBuild.2.0.3\build\Microsoft.TypeScript.MSBuild.props" Condition="Exists('..\..\lib\Microsoft.TypeScript.MSBuild.2.0.3\build\Microsoft.TypeScript.MSBuild.props')" />
Note: the ..\..\lib folder is correct, that is my package folder.
It seems all correct (except the minor trap, that Microsoft.TypeScript.targets file shipped with the package contains invalid vstsc parameter (output folder).
This gives build error, which proves that this msbuild task is in effect. After correcting this annoying bug (which will arise always when refreshing packages) build is successful.
However...
Using SysInternals processexplorer I see that not the installed (NuGet) tsc.exe is called, instead this one:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe
Wby... ?. How to configure my project (preferably with NuGet) to use the tsc.exe I want?
All I did to create above mess is...
Installing visual studio 2017 while working on visual studio 2015.
And I stopped the visual studio 2017 installation as I thought I would do it in another day.
So the setup application has removed my installed typescript plugin. All you have to do is
install type script for Visual Studio 2015. You can download the setup from bellow link.
https://www.microsoft.com/en-us/download/details.aspx?id=48593
Based on your description, I create a demo and reproduce your issue on our side. If you want to use C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe, please refer to the following steps.
1.Right-Click -> Unload Project
2.Right-Click -> Edit
replace references to
Microsoft.TypeScript.Default.props
The import should look something like:
<Import
Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props"
Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />
Microsoft.TypeScript.targets
The import should look something like:
<Import
Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets"
Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
For more information, please refer to:
https://github.com/Microsoft/TypeScript/wiki/Configuring-MSBuild-projects-to-use-NuGet

Build VS 2015 extension on build server without VS installed?

Is it possible to build a Visual Studio 2015 extension project on a build server (TeamCity agent) without Visual Studio installed? What kind of SDK do we need to install?
At the moment we receive the following error message:
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\Portable\v4.6\Microsoft.Portable.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
So there is definitely some kind of SDK missing.
Microsoft.VSSDK.BuildTools
Contains targets and tools to enable the building of managed VSIX
projects without VSSDK MSI installed. Only for VS 2015 and onwards
Additional packages that may be of interest:
https://www.nuget.org/profiles/VisualStudioExtensibility
Using #weir's answer almost worked - the project built successfully, but it failed to produce a VSIX container at the end. For some reason the Nuget package hadn't added the necessary Import to the .csproj to bring in the VsSDK.targets, so the VSIX targets were missing and never got executed.
Here are the steps which worked for me:
Edit the VSIX project .csproj file, and remove Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />. This will fail on the build server where the VSSDK doesn't exist in the VSToolsPath.
In the VS2015 IDE, open the Nuget Package Manager for the project, and install Microsoft.VSSDK.BuildTools (I used v14.3.25407)
Back in the .csproj file, find the import which the Nuget package added, e.g. <Import Project="..\packages\Microsoft.VSSDK.BuildTools.14.3.25407\build\Microsoft.VSSDK.BuildTools.targets" .../> and add another one below it for the VsSDK.targets file (inside the tools directory), <Import Project="..\packages\Microsoft.VSSDK.BuildTools.14.3.25407\tools\vssdk\Microsoft.VsSDK.targets" .../>
It looks like you have to install the Portable Library Tools on the build agent. You can download them from the VS Gallery and install them without having VS on the build agent using the following parameter /buildmachine.
Download Microsoft Build Tools 2015

Where is Microsoft.Web.Publishing.targets?

My MSBuild proj file is referencing Microsoft.Web.Publishing.targets. Even though microsoft says MSBuild is standalone installation, i dont think this file is part of MSBuild.
I am trying to setup a build server. and i don't see this file at this location. We have installed .Net 4.5.2 installed on that server.
C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\vXX.X\Web\Microsoft.Web.Publishing.targets
After researching I found, I have to install VisualStudio to get this at that location.
Questions
Is there any way to install this Target (and other Targets at this location) without having to install visual studio?
Yes, you can use the MSBuild.Microsoft.VisualStudio.Web.targets package.

Use specific TypeScript compiler version in Visual Studio

I wonder if there's a way to set specific TypeScript compiler version for project in Visual Studio. So I could configure a project to always use version 1.0, even if new versions would be released.
I know it was not possible before and I wonder if things changes after TypeScript matured to 1.0 version.
I noticed that now Visual Studio creates <TypeScriptToolsVersion>0.9</TypeScriptToolsVersion> property in a project file, but couldn't find any documentation about it.
If you try to compile a project with <TypeScriptToolsVersion>0.9</TypeScriptToolsVersion> using TypeScript version 1.0 you'll get the following error:
Your project file uses a different version of the TypeScript compiler and tools than is currently installed on this machine. No compiler was found at C:\Program Files (x86)\Microsoft SDKs\TypeScript\0.9\tsc.exe. You may be able to fix this problem by changing the element in your project file.
So it's preventing you from compiling with newer version. It does not however put the compiler into some 0.9 compatibility mode.
But if you have TypeScript 0.9 installed, it will compile against that version. So yes, you can force a specific version of the TypeScript compiler using the attribute.
Basically what the <TypeScriptToolsVersion> do is that it changes the path to the compiler:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\<TypeScriptToolsVersion>\tsc.exe
I have solved it by adding $(TypeScriptToolsVersion)\ after TypeScript\ in the condition statement.
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets"
Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\$(TypeScriptToolsVersion)\Microsoft.TypeScript.targets')" />
Visual Studio Version -> VS2013
Install Typescript 1.8 -> https://visualstudiogallery.msdn.microsoft.com/9d0e9172-244a-4943-94e5-bd24dffd9536
Open the folder location of your project e.g. Right click on your project > Open Folder in File Explorer
Find and open the project file via text editor e.g. WebApplication1.csproj
Find the "TypeScriptToolsVersion" tag under the "PropertyGroup" element and use 1.8. Like so,
<PropertyGroup>
......
<IISExpressUseClassicPipelineMode />
<TypeScriptToolsVersion>1.8</TypeScriptToolsVersion>
</PropertyGroup>
We can exclude type script file compilation in visual studio using below line in csproj file.
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
after <TypeScriptToolsVersion>0.9</TypeScriptToolsVersion> this line.

Resources