Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

MSBuildifying gulpified node #237

Merged
merged 2 commits into from
Mar 1, 2017
Merged

MSBuildifying gulpified node #237

merged 2 commits into from
Mar 1, 2017

Conversation

moozzyk
Copy link
Contributor

@moozzyk moozzyk commented Feb 25, 2017

  • Creating an MSBuild project for the TS client
  • Adding project references to the TS client project from projects that need the client - (ensures the correct targets dependency graph and prevents building the client multiple times and related races)
  • Removing gulp tasks from individual projects (allows containing npm only in the TS client source and node tests)
  • Using incremental compilation to build the TS client only when inputs change (prevents building the client multiple times or when not needed at all)
  • Removing npm install from all the projects (takes up to 10 seconds even if there is nothing to restore) - npm packages will still be installed when running full build (if needed) or need to be installed manually

@moozzyk
Copy link
Contributor Author

moozzyk commented Feb 25, 2017

VS does not like this change...

@moozzyk
Copy link
Contributor Author

moozzyk commented Feb 25, 2017

VS should be fixed now.

<RemoveDir Directories="$(SignalRClientDistFolder)" />
</Target>

<Import Project="$(MSBuildThisFileDirectory)\..\..\build\repo.targets" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is no longer needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, remove this.


<Import Project="..\..\build\common.props" />
<PropertyGroup>
<TargetFramework>netstandard1.0</TargetFramework>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need: <IsPackable>false</IsPackable>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does a typescript project need a target framework?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to pretend it's a csproj otherwise project references did not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it could not be open in VS

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this even a typescript project?

Copy link
Contributor

@natemcmaster natemcmaster Feb 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't need to reference Microsoft.NET.Sdk.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above - it makes project references work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify - currently there is no Typescript support/tooling for VS2017. I wanted to see what they did in previous versions and if you create a "Typescript project" in VS2015 it will be a *.csproj. I tried using their MSBuild tasks from VS2015 but they are compiled against .NET Framework and "our" MSBuild could not load them. When they have tools for VS2017 and netcore MSBuild tasks we need to make sure that there is an easy way to use the latest version of the compiler (i.e. you don't have to reinstall typescript MSBuild/tools if you want to move to a new compiler version)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidfowl
Copy link
Member

Does this still work with VS code?

</Target>

<Target Name="RestoreNpm" AfterTargets="Restore">
<Target Name="RestoreNpm">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this from the lifecycle?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a mistake. I originally depended on this target directly but I decided not to do this anymore because it adds at least a few secs to the build even if there is nothing to install. Will revert this change.

@@ -15,6 +15,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.SignalR.Client.TS\Microsoft.AspNetCore.SignalR.Client.TS.csproj" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try adding ReferenceOutputAssembly="false" to all ProjectReference to the TS project. This will suppress NuGet attempting to use the project reference as a compile reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turned out that I can't do that. With this settings I can build from command line but when I build with VS it fails to build the project due to:
Cannot find project info for 'C:\Source\SignalR-Core\src\Microsoft.AspNetCore.SignalR.Client.TS\Microsoft.AspNetCore.SignalR.Client.TS.csproj'. This can indicate a missing project reference.

<RemoveDir Directories="$(SignalRClientDistFolder)" />
</Target>

<Import Project="$(MSBuildThisFileDirectory)\..\..\build\repo.targets" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, remove this.

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
Copy link
Contributor

@natemcmaster natemcmaster Feb 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't need to reference Microsoft.NET.Sdk.

</PropertyGroup>

<ItemGroup>
<Inputs Include="*.ts;" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how well VS does with this project. You might try using None instead so VS recognizes the files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VS showed the files just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also able to build the ts client.

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: suggest changing extension to .proj. This isn't a C# project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started with .proj but VS refused to add it to the solution. Hence changing to project to pretend it's a .csproj

@moozzyk
Copy link
Contributor Author

moozzyk commented Feb 27, 2017

@davidfowl - VS Code should work. I plugged in things to MSBuild but under the cover it sill invokes npm/gulp to build things. This has not changed.

@natemcmaster
Copy link
Contributor

My only hesitation to this is that we're abusing what ProjectReference and Microsoft.NET.Sdk are meant to do, and this may be fragile. There are other ways to enforce build dependencies that may be cleaner, such as adding a BeforeBuild target to invoke MSBuild on the TS project, and using Project Dependencies in the solution to ensure build order.

@moozzyk
Copy link
Contributor Author

moozzyk commented Feb 27, 2017

@natemcmaster - this needs to be a .csproj because VS otherwise won't open it why using BeforeBuild (which I believe adds magic and requires creating additional targets in each project to have it under control) is better than a project dependency?
A bit more context: TypeScript tools are not available for VS2017 and in VS2015 a typescript project is... a .csproj (to be fair, it creates a host which is the cs part as far as I understand but apparently there isn't really a TypeScript project in the ecosystem AFAICT)

@moozzyk
Copy link
Contributor Author

moozzyk commented Feb 28, 2017

🆙📅

<Exec Command="npm run gulp -- --gulpfile $(MSBuildThisFileDirectory)gulpfile.js build-ts-client" />
</Target>

<Target Name="Clean">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This target will be overridden by Microsoft.NET.Sdk because this project has implicit top/bottom imports. If you want to override this target, use explicit imports instead. Example:

<Project>
  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

   <!-- regular project stuff here -->

  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

  <!-- Override default SDK targets-->
  <Target Name="Clean" />
  <Target Name="Build" />

</Project>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this results in the following build warnings:
warning MSB4011: "C:\Users\XXXX\AppData\Local\Microsoft\dotnet\sdk\1.0.0-rc4-004913\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets" cannot be imported again. It was already imported at "C:\source\SignalR-Core\src\Microsoft.AspNetCore.SignalR.Client.TS\Microsoft.AspNetCore.SignalR.Client.TS.csproj (30,3)". This is most likely a build authoring error. This subsequent import will be ignored.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does your file say <Project> or <Project Sdk="microsoft.net.sdk">?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see - it did say <Project Sdk="microsoft.net.sdk"> - I did not notice it that it should have been removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without Sdk attribute on Project it does work indeed. I decided however to use AfterTargets. The equivalence between the Sdk attribute and Imports is magic and we cannot override the Build target anyways.

<TargetFrameworks>netcoreapp1.1;net46</TargetFrameworks>
<TargetFrameworks>netcoreapp1.1</TargetFrameworks>
<PreserveCompilationContext>true</PreserveCompilationContext>
<OutputType>Exe</OutputType>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PreserveCompilationContext and OutputType are not required. These are the default settings for Microsoft.NET.Sdk.Web projects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@@ -3,38 +3,31 @@
<Import Project="..\..\build\common.props" />

<PropertyGroup>
<TargetFrameworks>netcoreapp1.1;net46</TargetFrameworks>
<TargetFrameworks>netcoreapp1.1</TargetFrameworks>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: make this singular TargetFramework

@analogrelay
Copy link
Contributor

Given that there aren't TypeScript tools for 2017 yet, I'm OK with using a csproj here. Let's be prepared to move over to a tsproj-based system when it releases though.

- Creating an MSBuild project for the TS client
- Adding project references to the TS client project from projects that need the client - (ensures the correct targets dependency graph and prevents building the client multiple times and related races)
- Removing gulp tasks from individual projects (allows containing npm only in the TS client source and node tests)
- Using incremental compilation to build the TS client only when inputs change (prevents building the client multiple times or when not needed at all)
- Removing `npm install` from all the projects (takes up to 10 seconds even if there is nothing to restore) - npm packages will still be installed when running full build (if needed) or need to be installed manually
@moozzyk moozzyk force-pushed the pawelka/ts-msbuild branch from 61cfc68 to 75b8249 Compare March 1, 2017 19:04
@moozzyk moozzyk merged commit 0162c19 into dev Mar 1, 2017
@moozzyk moozzyk deleted the pawelka/ts-msbuild branch March 4, 2017 03:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants