Skip to content

Commit

Permalink
support old fsproj (#9)
Browse files Browse the repository at this point in the history
add more cli options:

`--msbuild` => path to msbuild
`--dotnetcli` => path to dotnet, used for "dotnet msbuild"
`--msbuild-host` => what msbuild host to run, to force specific or auto (oldsdk/dotnetsdk). By default for oldsdk is `msbuild` and dotnetsdk is `dotnet`  

### Old fsproj parser

Use `msbuild` from command line to ask msbuild info about the project (not using msbuild as library)

How works:

- override the `CoreCompile` target, to gather info about the project properties (OutputType, etc)
- convert the msbuild properties to fsc args, using the Fsc task code

To override the `CoreCompile` target, the `CustomAfterMicrosoftCommonTargets` property is used as hook to import the generate .target file after F# targets are imported (msbuild override targets with same name, based on import sequence)

To convert msbuild properties to fsc compiler args, use the same Fsc msbuild task class code.

- `Fsc` msbuild task from microsoft/visualfsharp repo
- msbuild classes from mono/mono repo

The strategy for `msbuild properties -> fsc args` can be customized

Additional:

- move repo to .net core 2.0
- `dotnet-proj-info` support `netcoreapp2.0` framework
- `Dotnet.ProjInfo` support `netstandard2.0` framework
- the `Fsc` task is not bundled with `Dotnet.ProjInfo`, so clients can pin another version if needed
  • Loading branch information
enricosada authored Oct 25, 2017
1 parent d47494a commit 144a23b
Show file tree
Hide file tree
Showing 39 changed files with 876 additions and 149 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,5 @@ _Pvt_Extensions
# Repo-specific files

.dotnetsdk
/.paket/
/paket-files/
Binary file added .paket/paket.bootstrapper.exe
Binary file not shown.
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: csharp

mono: 5.2.0
dotnet: 2.0.0

install:
# workaround for missing .net 4.5 targing pack
- export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/

script:
- dotnet pack -v n
- dotnet test -v n

matrix:
include:
- os: linux
dist: trusty
sudo: required
- os: osx
osx_image: xcode9
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@ see `examples` directory

## Build

to create packages:
Run:

```bash
dotnet build
```
set VERSION=1.2.3
build.cmd

To run tests:

```bash
dotnet test -v n
```

will create packages with version `1.2.3` in `artifacts\nupkgs`
To create packages:

```bash
dotnet pack
```

will create packages in `artifacts\nupkgs`

pass `/p:Version=1.2.3` to create a package with version `1.2.3`

20 changes: 20 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
image:
- Visual Studio 2017

before_build:
- ps: >-
$buildId = $env:APPVEYOR_BUILD_NUMBER.PadLeft(5, '0');
$versionSuffixPR = "-PR$($env:APPVEYOR_PULL_REQUEST_NUMBER)-$buildId";
$branchName = "$env:APPVEYOR_REPO_BRANCH".Replace("_","");
$versionSuffixBRANCH = "-$branchName-$buildId";
$env:VersionSuffix = if ("$env:APPVEYOR_REPO_TAG" -eq "true") { "" } else { if ("$env:APPVEYOR_PULL_REQUEST_NUMBER") { $versionSuffixPR } else { $versionSuffixBRANCH } };
build_script:
- cmd: echo vs %VersionSuffix%"
- cmd: dotnet pack -v n
- cmd: dotnet test -v n

artifacts:
- path: bin\nupkg\*.nupkg
name: nupkgs
type: NuGetPackage
13 changes: 0 additions & 13 deletions build.cmd

This file was deleted.

26 changes: 26 additions & 0 deletions build.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project ToolsVersion="15.0">

<Import Project="src\Directory.Build.props" />

<Target Name="Build">
<Exec Command='dotnet build src/dotnet-proj-info' />
</Target>

<Target Name="Restore">
<Exec Command="$(MonoOrEmpty)paket.bootstrapper.exe" WorkingDirectory=".paket" ConsoleToMSBuild="true" />
<Exec Command="$(MonoOrEmpty)paket.exe restore" WorkingDirectory=".paket" ConsoleToMSBuild="true" />
</Target>

<Target Name="Pack">
<RemoveDir Directories="$(NupkgsDir)" />
<Exec Command='dotnet pack src/dotnet-proj-info -c Release -o "$(NupkgsDir)" /p:Version=$(Version)' />
<Exec Command='dotnet pack src/Dotnet.ProjInfo -c Release -o "$(NupkgsDir)" /p:Version=$(Version)' />
</Target>

<Target Name="Test">
<Exec Command='dotnet test -v n' WorkingDirectory="test" IgnoreStandardErrorWarningFormat="true" />
</Target>

<Target Name="VSTest" DependsOnTargets="Test" />

</Project>
52 changes: 0 additions & 52 deletions examples/.vscode/launch.json

This file was deleted.

17 changes: 0 additions & 17 deletions examples/.vscode/tasks.json

This file was deleted.

1 change: 0 additions & 1 deletion examples/NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<packageSources>
<clear />
<add key="nuget-org" value="https://api.nuget.org/v3/index.json" />
<add key="netcorecli dev feed" value="https://www.myget.org/F/netcorecli-fsc/api/v3/index.json" />
<add key="dotnet-proj-info dev feed" value="https://www.myget.org/F/dotnet-proj-info/api/v3/index.json" />
</packageSources>
</configuration>
25 changes: 13 additions & 12 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,42 @@

First restore the sample the packages and the tool

```
```bash
dotnet restore tools
dotnet restore c1
dotnet restore sdk1/c1
```

**NOTE** Because is a dotnet cli command, must be executed from same directory of project
where is declared. The project can be passed, if not it search the working directory
for a project (single .*proj)

```
```bash
cd tools
```

and

```
dotnet proj-info ..\c1\c1.fsproj --project-refs
Some examples of commands:

```bash
dotnet proj-info ../sdk1/c1/c1.fsproj --project-refs
```

or

```
dotnet proj-info ..\c1\c1.fsproj --fsc-args
```bash
dotnet proj-info ../sdk1/c1/c1.fsproj --fsc-args
```

or

```
dotnet proj-info ..\c1\c1.fsproj --get-property OutputType Version Configuration
```bash
dotnet proj-info ../sdk1/c1/c1.fsproj --get-property OutputType Version Configuration
```

It's possibile to pass usual .NET Core Tools arguments (like `-c`, `-f`, `-r`).

See `--help` for more info

```
dotnet proj-info ..\l1\l1.fsproj --gp MyCustomProp OutputType Version Configuration -c Release
```bash
dotnet proj-info ../sdk1/l1/l1.fsproj --gp MyCustomProp OutputType Version Configuration -c Release
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions examples/tools/tools.proj
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<DotNetCliToolReference Include="dotnet-proj-info" Version="0.6.0" />
</ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

// the Fsc build task
github Microsoft/visualfsharp:Visual-Studio-2017-Version-15.4 src/fsharp/FSharp.Build/Fsc.fs
github Microsoft/visualfsharp:Visual-Studio-2017-Version-15.4 src/fsharp/FSharp.Build/Microsoft.FSharp.Targets

// msbuild classes from Mono
github mono/mono:mono-5.2.0.224 mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/CommandLineBuilder.cs
github mono/mono:mono-5.2.0.224 mcs/class/Microsoft.Build.Framework/Microsoft.Build.Framework/ITaskItem.cs
github mono/mono:mono-5.2.0.224 mcs/class/Microsoft.Build.Framework/Microsoft.Build.Framework/ITaskItem2.cs
github mono/mono:mono-5.2.0.224 mcs/class/Microsoft.Build.Utilities/Mono.XBuild.Utilities/MSBuildUtils.cs
github mono/mono:mono-5.2.0.224 mcs/class/Microsoft.Build.Utilities/Mono.XBuild.Utilities/ReservedNameUtils.cs
github mono/mono:mono-5.2.0.224 mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/TaskItem.cs
12 changes: 12 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

GITHUB
remote: Microsoft/visualfsharp
src/fsharp/FSharp.Build/Fsc.fs (cc1b137bc17f401a0cc669ff8fc598714d0fe652)
src/fsharp/FSharp.Build/Microsoft.FSharp.Targets (cc1b137bc17f401a0cc669ff8fc598714d0fe652)
remote: mono/mono
mcs/class/Microsoft.Build.Framework/Microsoft.Build.Framework/ITaskItem.cs (14f2c814ccc4b98f11dae3074ba6a081956e9079)
mcs/class/Microsoft.Build.Framework/Microsoft.Build.Framework/ITaskItem2.cs (14f2c814ccc4b98f11dae3074ba6a081956e9079)
mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/CommandLineBuilder.cs (14f2c814ccc4b98f11dae3074ba6a081956e9079)
mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/TaskItem.cs (14f2c814ccc4b98f11dae3074ba6a081956e9079)
mcs/class/Microsoft.Build.Utilities/Mono.XBuild.Utilities/MSBuildUtils.cs (14f2c814ccc4b98f11dae3074ba6a081956e9079)
mcs/class/Microsoft.Build.Utilities/Mono.XBuild.Utilities/ReservedNameUtils.cs (14f2c814ccc4b98f11dae3074ba6a081956e9079)
6 changes: 5 additions & 1 deletion src/PackagesInfo.props → src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<Authors>Enrico Sada</Authors>
<PackageProjectUrl>https://github.com/enricosada/dotnet-proj-info/</PackageProjectUrl>
<PackageTags>mbuild;dotnet;sdk;csproj;fsproj</PackageTags>
<RepositoryUrl>https://github.com/enricosada/dotnet-proj-info.git</RepositoryUrl>

<RepoRootDir>$([System.IO.Path]::GetFullPath("$(MSBuildThisFileDirectory)\.."))</RepoRootDir>
<NupkgsDir>$(RepoRootDir)/bin/nupkg</NupkgsDir>
<Version Condition=" '$(Version)' == '' ">0.8.0$(VersionSuffix)</Version>
<MonoOrEmpty Condition=" '$(OS)' != 'Windows_NT' ">mono </MonoOrEmpty>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions src/Dotnet.ProjInfo.Helpers/Dotnet.ProjInfo.Helpers.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\paket-files\mono\mono\mcs\class\Microsoft.Build.Utilities\Microsoft.Build.Utilities\CommandLineBuilder.cs" />
<Compile Include="..\..\paket-files\mono\mono\mcs\class\Microsoft.Build.Framework\Microsoft.Build.Framework\ITaskItem.cs" />
<Compile Include="..\..\paket-files\mono\mono\mcs\class\Microsoft.Build.Framework\Microsoft.Build.Framework\ITaskItem2.cs" />
<Compile Include="..\..\paket-files\mono\mono\mcs\class\Microsoft.Build.Utilities\Microsoft.Build.Utilities\TaskItem.cs" />
<Compile Include="..\..\paket-files\mono\mono\mcs\class\Microsoft.Build.Utilities\Mono.XBuild.Utilities\MSBuildUtils.cs" />
<Compile Include="..\..\paket-files\mono\mono\mcs\class\Microsoft.Build.Utilities\Mono.XBuild.Utilities\ReservedNameUtils.cs" />
</ItemGroup>

</Project>
30 changes: 26 additions & 4 deletions src/Dotnet.ProjInfo/Dotnet.ProjInfo.fsproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.6;net45</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard1.6;net45</TargetFrameworks>
<Description>Get msbuild info</Description>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.6' ">
<!-- old fsproj is not supported on netstandard1.6 -->
<Compile Include="ExternalFSharp\MissingApi.fs" />
<Compile Include="ExternalFSharp\FscConfig.fs" />

<ProjectReference Include="..\Dotnet.ProjInfo.Helpers\Dotnet.ProjInfo.Helpers.csproj" PrivateAssets="All" />

<EmbeddedResource Include="..\..\paket-files\Microsoft\visualfsharp\src\fsharp\FSharp.Build\Microsoft.FSharp.Targets" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\dotnet-proj-info\Inspect.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FSharp.Core" Condition=" '$(TargetFramework)' == 'netstandard1.6' " Version="4.1.*" />
<PackageReference Include="FSharp.Core" Condition=" '$(TargetFramework)' == 'net45' " Version="4.0.0.1" />
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
</ItemGroup>

<Import Project="..\PackagesInfo.props" />
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
<!-- no need to reference System.ValueTuple nupkg on net45 because use FSharp.Core v4.0 -->
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
</PropertyGroup>

<!-- HACK: p2p of type project, not package (ref https://github.com/NuGet/Home/issues/3891 ) -->
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeP2POutput</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<Target Name="IncludeP2POutput" Condition=" '$(TargetFramework)' != 'netstandard1.6' ">
<ItemGroup>
<BuildOutputInPackage Include="$(MSBuildProjectDirectory)/$(OutputPath)Dotnet.ProjInfo.Helpers.dll" />
</ItemGroup>
</Target>

</Project>
Loading

0 comments on commit 144a23b

Please sign in to comment.