Can not configure which Typescript compiler to use in VS 2015 - visual-studio

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

Related

What is the default reference path for Visual Studio extensions?

I'm creating a Visual Studio Extension. This is a VSIX project.
I've added a reference to the project which I installed using NuGet.
At runtime, however, an error message is thrown. Cannot find file.... [name of dll].
What I would like to do is try and manually install this dll to the reference path that Visual Studio uses, so that it can resolve correctly.
Looks like your problem is very similar to this
But also there is a solution what we are using in our extensions.
You can create your own installer and move all necessary files into your specific folder. For this behavior you need to specify full path to your main integration dll in pkgdef
"CodeBase"="C:\Program Files (x86)\CompanyName\ProductName\integration.dll"
and vsixmanifest
<Asset Type="Microsoft.VisualStudio.MefComponent" Path="C:\Program Files (x86)\CompanyName\ProductName\integration.dll" />
files.
For VS2019 Community pkgdef and vsixmanifest should be placed here c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\
Subscribe on AppDomain.CurrentDomain.AssemblyResolve. Wait when specific assembly with specific version! required - and load it from your folder (C:\Program Files (x86)\CompanyName\ProductName).

How to install vstest.console.exe offline

I am supposed to do an offline installation of vstest.console.exe in the folder path as follows: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow
I have tried using offline packages such as vs_testagent.exe and vs_testcontroller.exe according to the following link: https://learn.microsoft.com/en-us/visualstudio/install/create-a-network-installation-of-visual-studio. However, these packages do not contain vstest.console.exe.
I am also unable to do a full installation of VS2017 due to space issues. Do anyone have any suggestions? Thanks.
Download the nuget package: Microsoft.TestPlatform, rename it a zip file. Open the zip file, you will find all you need from this folder: .\tools\net451\Common7\IDE\Extensions\TestPlatform, including vstest.console.exe, testhost.**.exe, QTAgent.exe, datacollector.exe.
If you added the nuget package to project, it just downloads the package to packages folder and won't complie to bin, so you have to add a Post-Build event to copy files to bin folder from the packages folder.
You are looking for "Build Tools for Visual Studio" (Microsoft login required). It will give you an installer "vs_BuildTools.exe", which will install by default the build tools in:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools
(by default)
Two versions of vstest console were installed when I ran it:
...\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe
...\Common7\IDE\Extensions\TestPlatform\vstest.console.exe
I do not know why, nor how they are different. I use the first one.
I used the chocolatey package visualstudio2019testagent to install VS 2019 Test Agent.
Not sure if this would help someone in the future.
Download the Visual Studio Build Tools installer from https://my.visualstudio.com/Downloads?q=build%20tools%20for%20visual%20studio
Run the installer, click the tab Individual components and select Testing tool core features - Build Tools
After installation the vstest.console.exe is located in folder
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TestWindow

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')" />

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

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)

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

Resources