Skip to content

Commit

Permalink
Workaround problems when opening solution files in Visual Studio (dot…
Browse files Browse the repository at this point in the history
…net#4569)

Changes:

* Condense Routing.sln into HttpAbstractions.sln
* Workaround NU1105 by adding all ProjectReferences to the .sln
* Workaround exceptions in the ReferencesHostBridge by moving Reference items to a temporary item group
* Add a 'startvs.cmd' script for launching VS with the right env variables
* Remove RangeHelper test project
* Move RangeHelper tests into StaticFiles.Tests and add target for NPM restore
  • Loading branch information
natemcmaster authored Dec 11, 2018
1 parent 4c5debd commit 5151e7b
Show file tree
Hide file tree
Showing 50 changed files with 492 additions and 263 deletions.
39 changes: 0 additions & 39 deletions Microsoft.AspNetCore.sln

This file was deleted.

7 changes: 7 additions & 0 deletions build/repo.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@

<ProjectToExclude Include="@(SamplesProject)" Condition="'$(BuildSamples)' == 'false' "/>

<!-- These projects use 'legacy' csproj, which is not supported by dotnet-msbuild. -->
<ProjectToExclude Include="
$(RepositoryRoot)src\Servers\HttpSys\samples\TestClient\TestClient.csproj;
$(RepositoryRoot)src\Middleware\WebSockets\samples\TestServer\TestServer.csproj;
"
Condition=" '$(MSBuildRuntimeType)' == 'Core' " />

<!-- Exclude the websockets samples for now because they use classic .csproj, which is not yet supported in our build. -->
<ProjectToExclude Include="
$(RepositoryRoot)src\Middleware\WebSockets\samples\**\*.csproj;
Expand Down
15 changes: 15 additions & 0 deletions build/repo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@
<GetArtifactInfoDependsOn Condition="'$(_ProjectsOnly)' != 'true'">$(GetArtifactInfoDependsOn);ResolveRepoInfo</GetArtifactInfoDependsOn>
</PropertyGroup>

<PropertyGroup>
<RestoreDependsOn Condition=" '$(SkipNpm)' != 'true' ">$(RestoreDependsOn);RestoreNpm</RestoreDependsOn>
</PropertyGroup>

<Target Name="RestoreNpm" Condition="@(NpmProjectDirectory->Count()) != 0">
<Message Text="Restoring NPM modules" Importance="high" />

<PropertyGroup>
<NpmInstallCommand Condition=" '$(CI)' != 'true' ">install --no-optional</NpmInstallCommand>
<NpmInstallCommand Condition=" '$(CI)' == 'true' ">ci</NpmInstallCommand>
</PropertyGroup>

<Exec Command="npm $(NpmInstallCommand)" WorkingDirectory="%(NpmProjectDirectory.Identity)" Condition=" '%(NpmProjectDirectory.Identity)' != '' " />
</Target>

<Target Name="PrepareOutputPaths">
<MakeDir Directories="$(ArtifactsDir);$(BuildDir)" />
</Target>
Expand Down
91 changes: 69 additions & 22 deletions docs/BuildFromSource.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
Build ASP.NET Core from Source
==============================

Building ASP.NET Core from source allows you tweak and customize ASP.NET Core, and
to contribute your improvements back to the project.
Building ASP.NET Core from source allows you tweak and customize ASP.NET Core, and to contribute your improvements back to the project.

## :warning: Temporary instructions
:warning: We are currently in the middle of restructing our source code. These instructions will likely change rapidly during November and December 2018.

We are currently in the middle of restructing our repositories. While this work is being done, the following instructions will help you be more productive while working on this repo.

1. Before opening a solution, run `build.cmd /p:_ProjectsOnly=true /p:SkipTests=true`. This will only build the projects which have merged into this repo, not the git submodules.
2. Use (or create) a solution which is scoped to your project file. The build system does not use .sln files. These only exist for developer productivity in Visual Studio, so feel free to adjust the projects in .sln files to match your workload.
3. Questions? Contact @aspnet for help.
See https://github.com/aspnet/AspNetCore/labels/area-infrastructure for known issues and to track ongoing work.

## Install pre-requistes

Expand Down Expand Up @@ -58,22 +53,66 @@ git submodule update --init --recursive

## Building in Visual Studio / Code

Before opening our .sln files in Visual Studio or VS Code, executing the following on command-line:
```
.\build.cmd /t:Restore
```
This will download required tools.
Before opening our .sln files in Visual Studio or VS Code, you need to perform the following actions.

1. Executing the following on command-line:
```
.\build.cmd /p:SkipTests=true /p:_ProjectsOnly=true
```
This will download required tools and build the entire repository once. At that point, you should be able to open .sln files to work on the projects you care about.

2. Use the `startvs.cmd` script to open Visual Studio .sln files. This script first sets required environment variables.

> :bulb: Pro tip: you will also want to run this command after pulling large sets of changes. Visual Studio will only build projects in a solution file, and makes a best effort to use other files on disk. If you pull many changes, the files on disk may be stale and will need to re-build.
### Solution files

We don't have a single .sln file for all of ASP.NET Core because Visual Studio doesn't currently handle projects of this scale.
Instead, we have many .sln files which include a sub-set of projects. These principles guide how we create and manage .slns:

1. Solution files are not used by CI or command line build scripts. They are for meant for use by developers only.
2. Solution files group together projects which are frequently edited at the same time.
3. Can't find a solution that has the projects you care about? Feel free to make a PR to add a new .sln file.

> :bulb: Pro tip: `dotnet new sln` and `dotnet sln` are one of the easiest ways to create and modify solutions.
### Known issue: NU1105

Opening solution files may produce an error code NU1105 with a message such

> Unable to find project information for 'C:\src\AspNetCore\src\Hosting\Abstractions\src\Microsoft.AspNetCore.Hosting.Abstractions.csproj'. Inside Visual Studio, this may be because the project is unloaded or not part of current solution. Otherwise the project file may be invalid or missing targets required for restore.
This is a known issue in NuGet (<https://github.com/NuGet/Home/issues/5820>) and we are working with them for a solution. See also <https://github.com/aspnet/AspNetCore/issues/4183> to track progress on this.

**The workaround** for now is to add all projects to the solution.

dotnet sln add C:\src\AspNetCore\src\Hosting\Abstractions\src\Microsoft.AspNetCore.Hosting.Abstractions.csproj


#### PATH

For VS Code and Visual Studio to work correctly, you must place the following location in your PATH.
For VS Code and Visual Studio and `dotnet` commands to work correctly, you must place the following location in your PATH.
Use the following commands to update the PATH variable in a command line window.

Windows (Command Prompt)

```batch
set PATH=%USERPROFILE%\.dotnet\x64;%PATH%
```

Windows (Powershell)

```ps1
$env:PATH="$env:USERPROFILE\.dotnet\x64;$env:PATH"
```
Windows: %USERPROFILE%\.dotnet\x64
Linux/macOS: $HOME/.dotnet

Linux/macOS:

```sh
export PATH="$HOME/.dotnet:$PATH"
```
This must come **before** any other installation of `dotnet`. In Windows, we recommend removing `C:\Program Files\dotnet` from PATH in system variables and adding `%USERPROFILE%\.dotnet\x64` to PATH in user variables.

<img src="http://i.imgur.com/Tm2PAfy.png" width="400" />
On Windows, we recommend using the `startvs.cmd` command to launch Visual Studio.

## Building on command-line

Expand All @@ -89,6 +128,14 @@ On macOS/Linux:
./build.sh
```

### Building a subset of the code

This repository is large. Look for `build.cmd`/`.sh` scripts in subfolders. These scripts can be used to invoke build and test on a smaller set of projects.

#### Known issue: not every subfolder has a build.cmd script

We'll be adding more. See https://github.com/aspnet/AspNetCore/issues/4247.

#### Build properties

Additional properties can be added as an argument in the form `/property:$name=$value`, or `/p:$name=$value` for short. For example:
Expand All @@ -99,8 +146,8 @@ Additional properties can be added as an argument in the form `/property:$name=$
Common properties include:

Property | Description
-------------------------|---------------------------------------------------------
BuildNumber | (string). A specific build number, typically from a CI counter
-------------------------|-------------------------------------------------------------------------------------------------------------
BuildNumberSuffix | (string). A specific build number, typically from a CI counter, which is appended to the pre-release label.
Configuration | `Debug` or `Release`. Default = `Debug`.
SkipTests | `true` or `false`. When true, builds without running tests.
NoBuild | `true` or `false`. Runs tests without rebuilding.
Expand All @@ -109,7 +156,7 @@ NoBuild | `true` or `false`. Runs tests without rebuilding.

After building ASP.NET Core from source, you will need to install and use your local version of ASP.NET Core.

- Run the installers produced in `artifacts/installers/` for your platform.
- Run the installers produced in `artifacts/{Debug, Release}/installers/` for your platform.
- Add a NuGet.Config to your project directory with the following content:

```xml
Expand All @@ -128,7 +175,7 @@ After building ASP.NET Core from source, you will need to install and use your l
- Update the versions on `PackageReference` items in your .csproj project file to point to the version from your local build.
```xml
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="3.0.0-alpha1-t000" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="3.0.0-preview-0" />
</ItemGroup>
```

Expand Down
1 change: 0 additions & 1 deletion eng/Baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@
<Package Id="Microsoft.AspNetCore.WebSockets" Version="2.1.1" />
<Package Id="Microsoft.AspNetCore.WebUtilities" Version="2.1.1" />
<Package Id="Microsoft.Net.Http.Headers" Version="2.1.1" />

</Baseline>
6 changes: 6 additions & 0 deletions eng/targets/CSharp.Common.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<Project>

<!-- For 'legacy' .csproj files, set map TargetFrameworkVersion back to TargetFramework -->
<PropertyGroup Condition=" '$(TargetFramework)' == '' AND '$(TargetFrameworks)' == '' ">
<TargetFramework>net$(TargetFrameworkVersion.Substring(1).Replace('.',''))</TargetFramework>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
</PropertyGroup>

<Import Project="Packaging.targets" />
<Import Project="ResolveReferences.targets" />
</Project>
8 changes: 7 additions & 1 deletion eng/targets/ResolveReferences.targets
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@
<ProjectReference Include="@(_ProjectReferenceByAssemblyName->'%(ProjectPath)')" />

<Reference Remove="@(_ProjectReferenceByAssemblyName)" />

<!-- Use _ReferenceTemp to workaround issues in Visual Studio which causes a conflict between Reference, packages, and projects. -->
<_ReferenceTemp Include="@(Reference)" />
<Reference Remove="@(Reference)" />
</ItemGroup>

<Target Name="ResolveCustomReferences" BeforeTargets="CollectPackageReferences;ResolveAssemblyReferencesDesignTime;ResolveAssemblyReferences" Condition=" '$(TargetFramework)' != '' ">
<ItemGroup>
<UnusedBaselinePackageReference Include="@(BaselinePackageReference)" Exclude="@(Reference);@(_ProjectReferenceByAssemblyName)" />
<Reference Include="@(_ReferenceTemp)" />
<_ReferenceTemp Remove="@(_ReferenceTemp)" />

<UnusedBaselinePackageReference Include="@(BaselinePackageReference)" Exclude="@(Reference);@(_ProjectReferenceByAssemblyName)" />
<!--
MSBuild does not provide a way to join on matching identities in a Condition,
but you can do a cartesian product of two item groups and filter out mismatched id's in a second pass.
Expand Down
3 changes: 3 additions & 0 deletions src/DataProtection/startvs.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ECHO OFF

%~dp0..\..\startvs.cmd %~dp0DataProtection.sln
Loading

0 comments on commit 5151e7b

Please sign in to comment.