Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…emWeb into main
  • Loading branch information
CZEMacLeod committed May 22, 2021
2 parents d59a965 + 024280e commit 3217506
Show file tree
Hide file tree
Showing 12 changed files with 325 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.Targets
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<None Include="Sdk\**"
Pack="true"
PackagePath="Sdk\" />
<None Include="README.md" />
<None Include="README.md" Condition="EXISTS('README.md')" />
<None Include="$(PackageLicensePath)"
Pack="true"
PackagePath="$(PackageLicenseFile)"
Expand Down
4 changes: 4 additions & 0 deletions MSBuild.SDK.SystemWeb.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "ExampleFullWebApplication",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSBuild.SDK.SystemWeb.Templates", "src\MSBuild.SDK.SystemWeb.Templates\MSBuild.SDK.SystemWeb.Templates.csproj", "{750A2B35-A9BB-488B-972C-31FEAB17CF3A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "docs", "docs\docs.csproj", "{9E629342-F10C-4EA4-A578-016DD5713C1F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -53,6 +55,8 @@ Global
{750A2B35-A9BB-488B-972C-31FEAB17CF3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{750A2B35-A9BB-488B-972C-31FEAB17CF3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{750A2B35-A9BB-488B-972C-31FEAB17CF3A}.Release|Any CPU.Build.0 = Release|Any CPU
{9E629342-F10C-4EA4-A578-016DD5713C1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E629342-F10C-4EA4-A578-016DD5713C1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# MSBuild.SDK.SystemWeb

[![Build Status](https://dev.azure.com/flexviews/MSBuild.SDKs.SystemWeb/_apis/build/status/CZEMacLeod.MSBuild.SDK.SystemWeb?branchName=main)](https://dev.azure.com/flexviews/MSBuild.SDKs.SystemWeb/_build/latest?definitionId=69&branchName=main)
[![Docs](https://img.shields.io/badge/Documentation-docs-lightgrey?logo=github)](https://czemacleod.github.io/MSBuild.SDK.SystemWeb/)

This MSBuild SDK is designed to allow for the easy creation and use of SDK (shortform) projects targeting ASP.NET 4.x using System.Web.

Expand All @@ -20,6 +21,10 @@ This is the basic SDK that enables Visual Studio 2019 to work with an ASP.Net 4.

This is a set of templates that allow for the easy creation of projects based on the MSBuild.SDK.SystemWeb project SDK type.

## Read The Docs

### [Documentation](https://czemacleod.github.io/MSBuild.SDK.SystemWeb/)

## How can I use these SDKs?

When using an MSBuild Project SDK obtained via NuGet (such as the SDKs in this repo) a specific version **must** be specified.
Expand Down
3 changes: 3 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ trigger:
branches:
include:
- main
paths:
exclude:
- docs/*

pr: none

Expand Down
58 changes: 58 additions & 0 deletions docs/Binding_Redirects/Autogenerating-Binding-Redirects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Autogenerating Binding Redirects

The template will, on compile, generate a copy of the current `web.config` with any required binding redirects added.
This file is written to the `bin` folder with the name `AssemblyName.dll.config` where `AssemblyName` is the name of your assembly.

You can set the `AssemblyName` by adding
```xml
<AssemblyName>MyAssemblyName</AssemblyName>
```
to your project file as normal.

If you get the error `Warning MSB3276 Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190. <project name here>`, then you can manually copy the
```xml
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
...
</assemblyBinding>
</runtime>
```
section from the generated `.dll.config` file to your web.config file, replacing the existing `assemblyBinding` node.

Alternatively, since the `.dll.config` file is based on your `web.config` file, you can just overwrite your `web.config` file with the `.dll.config` file.

If you want this to happen automatically, you can add the following to your project file.
```xml
<PropertyGroup>
<OverwriteAppConfigWithBindingRedirects>true</OverwriteAppConfigWithBindingRedirects>
</PropertyGroup>
```

This enables the following target in the SDK which will overwrite your web.config from the patched version if there are any changes.

```xml
<Target Name="UpdateConfigWithBindingRedirects" AfterTargets="AfterBuild" Condition="'$(OverwriteAppConfigWithBindingRedirects)'=='true'">
<ItemGroup>
<_DllConfig Remove="@(_DllConfig)" />
<_AppConfig Remove="@(_AppConfig)" />
<_ConfigFile Remove="@(_ConfigFileHash)" />
<_DllConfig Include="$(OutDir)$(AssemblyName).dll.config" />
<_AppConfig Include="web.config" />
</ItemGroup>
<GetFileHash Files="@(_DllConfig)">
<Output TaskParameter="Hash" PropertyName="_DllConfigHash" />
<Output TaskParameter="Items" ItemName="_DllConfigFileHash" />
</GetFileHash>
<GetFileHash Files="@(_AppConfig)">
<Output TaskParameter="Hash" PropertyName="_AppConfigHash" />
<Output TaskParameter="Items" ItemName="_AppConfigFileHash" />
</GetFileHash>
<ItemGroup>
<_ConfigFileHash Include="@(_DllConfigFileHash)" />
<_ConfigFileHash Include="@(_AppConfigFileHash)" />
</ItemGroup>
<Message Text="%(_ConfigFileHash.Identity): %(_ConfigFileHash.FileHash)" />
<Warning Text="Replacing web.config due to changes during compile - This should clear warning MSB3276 on next compile" File="web.config" Condition="'$(_DllConfigHash)'!='$(_AppConfigHash)'" />
<Copy SourceFiles="$(OutDir)$(AssemblyName).dll.config" DestinationFiles="web.config" Condition="'$(_DllConfigHash)'!='$(_AppConfigHash)'" />
</Target>
```
56 changes: 56 additions & 0 deletions docs/Binding_Redirects/How-to-show-Suggested-Binding-Redirects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# How to show Suggested Binding Redirects

The following may be useful if you need to see generated binding redirects.
e.g. if you want to manually add them to your `web.config`
```xml
<UsingTask TaskName="ShowBindingRedirects" TaskFactory="$(TaskFactory)" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<SuggestedBindingRedirects ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Reflection" />
<Using Namespace="System.Xml" />
<Using Namespace="Microsoft.Build.Framework" />
<Code Type="Fragment" Language="cs">
<![CDATA[
StringBuilder sb = new StringBuilder();
foreach(var sbr in SuggestedBindingRedirects) {
var an = new AssemblyName(sbr.ItemSpec);
var mvn = sbr.GetMetadata("MaxVersion");
byte []pt = an.GetPublicKeyToken();
sb.AppendLine("<assemblyBinding xmlns=\"urn:schemas-microsoft-com:asm.v1\">");
sb.AppendLine("\t<dependentAssembly>");
sb.Append("\t\t<assemblyIdentity name=\"");
sb.Append(an.Name);
sb.Append("\" publicKeyToken=\"");
if (pt is null) {
sb.Append("null");
} else {
for (int i=0;i<pt.GetLength(0);i++)
sb.AppendFormat("{0:x2}", pt[i]);
}
sb.Append("\" culture=\"");
sb.Append(an.CultureName);
sb.AppendLine("\" />");
sb.Append("\t\t<bindingRedirect oldVersion=\"0.0.0.0-");
sb.Append(mvn);
sb.Append("\" newVersion=\"");
sb.Append(mvn);
sb.AppendLine("\" />");
sb.AppendLine("\t</dependentAssembly>");
sb.AppendLine("</assemblyBinding>");
}
Log.LogMessage(MessageImportance.High,sb.ToString());
]]>
</Code>
</Task>
</UsingTask>

<Target Name="ShowBindingRedirects" AfterTargets="ResolveAssemblyReferences">
<ShowBindingRedirects SuggestedBindingRedirects="@(SuggestedBindingRedirects)" Condition="'@(SuggestedBindingRedirects)'!=''" />
</Target>
```
89 changes: 89 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# MSBuild.SDK.SystemWeb

[![Build Status](https://dev.azure.com/flexviews/MSBuild.SDKs.SystemWeb/_apis/build/status/CZEMacLeod.MSBuild.SDK.SystemWeb?branchName=main)](https://dev.azure.com/flexviews/MSBuild.SDKs.SystemWeb/_build/latest?definitionId=69&branchName=main)
[![Source](https://img.shields.io/badge/github-source-lightgrey?logo=github)](https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb)

This MSBuild SDK is designed to allow for the easy creation and use of SDK (shortform) projects targeting ASP.NET 4.x using System.Web.

## What's available

### [MSBuild.SDK.SystemWeb](SDK.md)

[![NuGet package](https://img.shields.io/nuget/v/MSBuild.SDK.SystemWeb.svg)](https://nuget.org/packages/MSBuild.SDK.SystemWeb)
[![NuGet downloads](https://img.shields.io/nuget/dt/MSBuild.SDK.SystemWeb.svg)](https://nuget.org/packages/MSBuild.SDK.SystemWeb)

This is the basic SDK that enables Visual Studio 2019 to work with an ASP.Net 4.x based project using a short form project file.

### [MSBuild.SDK.SystemWeb.Templates](Templates.md)

[![NuGet package](https://img.shields.io/nuget/v/MSBuild.SDK.SystemWeb.Templates.svg)](https://nuget.org/packages/MSBuild.SDK.SystemWeb)
[![NuGet downloads](https://img.shields.io/nuget/dt/MSBuild.SDK.SystemWeb.Templates.svg)](https://nuget.org/packages/MSBuild.SDK.SystemWeb)

This is a set of templates that allow for the easy creation of projects based on the MSBuild.SDK.SystemWeb project SDK type.

## How can I use these SDKs?

When using an MSBuild Project SDK obtained via NuGet (such as the SDKs in this repo) a specific version **must** be specified.

Either append the version to the package name:

```xml
<Project Sdk="MSBuild.SDK.SystemWeb/4.0.33">
...
```

Or omit the version from the SDK attribute and specify it in the version in `global.json`, which can be useful to synchronise versions across multiple projects in a solution:

```json
{
"msbuild-sdks": {
"MSBuild.SDK.SystemWeb" : "4.0.33"
}
}
```

Since MSBuild 15.6, SDKs are downloaded as NuGet packages automatically. Earlier versions of MSBuild 15 required SDKs to be installed.

For more information, [read the documentation](https://docs.microsoft.com/visualstudio/msbuild/how-to-use-project-sdk).

## What are MSBuild SDKS?
MSBuild 15.0 introduced new project XML for .NET Core that we refer to as SDK-style. These SDK-style projects looks like:

```xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
</Project>
```

At evaluation time, MSBuild adds implicit imports at the top and bottom of the project like this:

```xml
<Project Sdk="MSBuild.SDK.SystemWeb">
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>

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

# Useful Information

## Binding Redirects
- [How to show Suggested Binding Redirects](Binding_Redirects/How-to-show-Suggested-Binding-Redirects.md)
- [Autogenerating Binding Redirects](Binding_Redirects/Autogenerating-Binding-Redirects.md)

## Known Limitations
- ![GitHub issues by-label](https://img.shields.io/github/issues/CZEMacLeod/MSBuild.SDK.SystemWeb/known%20limitation?label=known%20limitations)
- ![GitHub issues by-label](https://img.shields.io/github/issues-closed/CZEMacLeod/MSBuild.SDK.SystemWeb/known%20limitation?label=known%20limitations)
- [Projects don't work with dotnet CLI tooling](https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb/issues/1)
- [Docker Containers](https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb/issues/9)
- [WebForms](https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb/issues/11)
- [VS Publish Command](https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb/issues/12)

## Templates
- [How to install and use the templates](Templates.md)
30 changes: 30 additions & 0 deletions docs/SDK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# MSBuild.SDK.SystemWeb

[![Build Status](https://dev.azure.com/flexviews/MSBuild.SDKs.SystemWeb/_apis/build/status/CZEMacLeod.MSBuild.SDK.SystemWeb?branchName=main)](https://dev.azure.com/flexviews/MSBuild.SDKs.SystemWeb/_build/latest?definitionId=69&branchName=main)
[![NuGet package](https://img.shields.io/nuget/v/MSBuild.SDK.SystemWeb.svg)](https://nuget.org/packages/MSBuild.SDK.SystemWeb)
[![NuGet downloads](https://img.shields.io/nuget/dt/MSBuild.SDK.SystemWeb.svg)](https://nuget.org/packages/MSBuild.SDK.SystemWeb)

Based on the discussion and ideas in [Add support for ASP.NET (non-Core) projects](https://github.com/dotnet/project-system/issues/2670)

## How can I use this SDKs?

When using an MSBuild Project SDK obtained via NuGet (such as the SDKs in this repo) a specific version **must** be specified.

Either append the version (as shown in the nuget shield above) to the package name:

```xml
<Project Sdk="MSBuild.SDK.SystemWeb/4.0.33">
...
```

Or omit the version from the SDK attribute and specify it in the version in `global.json`, which can be useful to synchronise versions across multiple projects in a solution:

```json
{
"msbuild-sdks": {
"MSBuild.SDK.SystemWeb" : "4.0.33"
}
}
```

You can also use the [templates](Templates.md) to easily create new projects.
52 changes: 52 additions & 0 deletions docs/Templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# MSBuild.SDK.SystemWeb.Templates

[![Build Status](https://dev.azure.com/flexviews/MSBuild.SDKs.SystemWeb/_apis/build/status/CZEMacLeod.MSBuild.SDK.SystemWeb?branchName=main)](https://dev.azure.com/flexviews/MSBuild.SDKs.SystemWeb/_build/latest?definitionId=69&branchName=main)
[![NuGet package](https://img.shields.io/nuget/v/MSBuild.SDK.SystemWeb.Templates.svg)](https://nuget.org/packages/MSBuild.SDK.SystemWeb)
[![NuGet downloads](https://img.shields.io/nuget/dt/MSBuild.SDK.SystemWeb.Templates.svg)](https://nuget.org/packages/MSBuild.SDK.SystemWeb)

## Installation

```cmd
dotnet new -i MSBuild.SDK.SystemWeb.Templates
```

## Updating

Optionally
```cmd
dotnet new --update-check
```
and
```cmd
dotnet new --update-apply
```
**N.B.** This applies to all installed templates.
```cmd
dotnet new -i MSBuild.SDK.SystemWeb.Templates
```
Should update you to the latest version even if you have them already installed.

## Usage

### CLI
```cmd
dotnet new systemweb
```
or
```cmd
dotnet new systemwebfull
```

To select the VB.Net version use the flag `-lang VB`
e.g.
```cmd
dotnet new systemweb -land VB
```

### Visual Studio 2019
Alternatively use the Visual Studio Add Project dialog.
You need to have enabled the Preview feature to show [.NET CLI Templates in Visual Studio](https://devblogs.microsoft.com/dotnet/net-cli-templates-in-visual-studio/) and have Visual Studio 16.8 Preview 2 or higher.

![Visual Studio New Project Dialog](https://raw.githubusercontent.com/CZEMacLeod/MSBuild.SDK.SystemWeb/main/src/MSBuild.SDK.SystemWeb.Templates/images/create-new-project.png)

You can find the new templates easily by selecting `System.Web` from the Project Type dropdown.
12 changes: 12 additions & 0 deletions docs/docs.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.Build.NoTargets">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Content Include="**\*.md" />
</ItemGroup>
<ItemGroup>
<Folder Include="Known_Limitations\" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions src/MSBuild.SDK.SystemWeb.Templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ You need to have enabled the Preview feature to show [.NET CLI Templates in Visu
![Visual Studio New Project Dialog](images/create-new-project.png)

You can find the new templates easily by selecting System.Web from the Project Type dropdown.

## Documentation

For more information see

[![Source](https://img.shields.io/badge/github-source-lightgrey?logo=github)](https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb)
[![Docs](https://img.shields.io/badge/github_pages-docs-lightgrey?logo=github)](https://czemacleod.github.io/MSBuild.SDK.SystemWeb/)
9 changes: 8 additions & 1 deletion src/MSBuild.SDK.SystemWeb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ Or omit the version from the SDK attribute and specify it in the version in `glo
}
```

You can also use the [templates](../MSBuild.SDK.SystemWeb.Templates) to easily create new projects.
You can also use the [templates](../MSBuild.SDK.SystemWeb.Templates) to easily create new projects.

## Documentation

For more information see

[![Source](https://img.shields.io/badge/github-source-lightgrey?logo=github)](https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb)
[![Docs](https://img.shields.io/badge/github_pages-docs-lightgrey?logo=github)](https://czemacleod.github.io/MSBuild.SDK.SystemWeb/)

0 comments on commit 3217506

Please sign in to comment.