-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/CZEMacLeod/MSBuild.SDK.Syst…
…emWeb into main
- Loading branch information
Showing
12 changed files
with
325 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ trigger: | |
branches: | ||
include: | ||
- main | ||
paths: | ||
exclude: | ||
- docs/* | ||
|
||
pr: none | ||
|
||
|
58 changes: 58 additions & 0 deletions
58
docs/Binding_Redirects/Autogenerating-Binding-Redirects.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
docs/Binding_Redirects/How-to-show-Suggested-Binding-Redirects.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters