-
Notifications
You must be signed in to change notification settings - Fork 330
Add Azure auth sample app #3988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
91c7b8d
Created sample app to demonstrate how all of the SqlClient packages w…
paulmedynski ac29841
Added the AzureAuthentication sample app to the main solution.
paulmedynski 064bccc
Added tracing and logging support.
paulmedynski 66bbe3e
Added .NET Framework support.
paulmedynski 9d6aa75
Removed BOMs and added package versions to help.
paulmedynski 1b49770
Merge branch 'main' into dev/paul/azure-samples
paulmedynski da3c27e
Lots of tidying-up and polish.
paulmedynski d8fbc3d
Addressed Copilot comments.
paulmedynski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
|
paulmedynski marked this conversation as resolved.
paulmedynski marked this conversation as resolved.
|
This file contains hidden or 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,35 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFrameworks>net481;net10.0</TargetFrameworks> | ||
|
paulmedynski marked this conversation as resolved.
|
||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <LangVersion>latest</LangVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- SqlClient Packages --> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Data.SqlClient" /> | ||
| <!-- | ||
| We include the AKV Provider to ensure there are no transitive dependency conflicts. It is | ||
| instantiated to ensure its assembly isn't elided, but we don't actually use it. | ||
| --> | ||
| <PackageReference Include="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" /> | ||
|
|
||
| <!-- Include the Azure package if a version for it was specified. --> | ||
| <PackageReference | ||
| Include="Microsoft.Data.SqlClient.Extensions.Azure" | ||
| Condition="'$(AzureVersion)' != ''" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- Other Packages --> | ||
| <ItemGroup> | ||
| <PackageReference Include="Azure.Identity" /> | ||
| <PackageReference Include="System.CommandLine" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- Generate code with the SqlClient package versions. --> | ||
|
paulmedynski marked this conversation as resolved.
|
||
| <Import Project="GeneratePackageVersions.targets" /> | ||
|
|
||
| </Project> | ||
This file contains hidden or 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,10 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
|
||
| <!-- We purposely do not include any parent Directory.Build.props files. --> | ||
|
|
||
| <PropertyGroup> | ||
| <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
This file contains hidden or 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,32 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
|
||
| <!-- We purposely do not include any parent Directory.Packages.props files. --> | ||
|
|
||
| <PropertyGroup> | ||
| <!-- Use SqlClient 6.1.4 if no version was specified. --> | ||
| <SqlClientVersion>6.1.4</SqlClientVersion> | ||
|
|
||
| <!-- Use AKV Provider 6.1.2 if no version was specified. --> | ||
| <AkvProviderVersion>6.1.2</AkvProviderVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- SqlClient Packages --> | ||
| <ItemGroup> | ||
| <PackageVersion Include="Microsoft.Data.SqlClient" Version="$(SqlClientVersion)" /> | ||
| <PackageVersion Include="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version="$(AkvProviderVersion)" /> | ||
|
|
||
| <!-- Declare a version for the Azure package if one was specified. --> | ||
| <PackageVersion | ||
| Include="Microsoft.Data.SqlClient.Extensions.Azure" | ||
| Version="$(AzureVersion)" | ||
| Condition="'$(AzureVersion)' != ''" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- Other Packages --> | ||
| <ItemGroup> | ||
| <PackageVersion Include="Azure.Identity" Version="1.17.1" /> | ||
| <PackageVersion Include="System.CommandLine" Version="2.0.3" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
111 changes: 111 additions & 0 deletions
111
doc/apps/AzureAuthentication/GeneratePackageVersions.targets
This file contains hidden or 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,111 @@ | ||
| <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
paulmedynski marked this conversation as resolved.
|
||
|
|
||
| <!-- Inline task that generates a static class whose properties expose package versions. --> | ||
| <UsingTask TaskName="GeneratePackageVersionsClass" | ||
| TaskFactory="RoslynCodeTaskFactory" | ||
| AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> | ||
| <ParameterGroup> | ||
| <Packages ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> | ||
| <Versions ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> | ||
| <Defaults ParameterType="Microsoft.Build.Framework.ITaskItem[]" /> | ||
| <Namespace ParameterType="System.String" Required="true" /> | ||
| <OutputFile ParameterType="System.String" Required="true" /> | ||
| </ParameterGroup> | ||
| <Task> | ||
| <Code Type="Fragment" Language="cs"> | ||
| <![CDATA[ | ||
| // Build a lookup from PackageVersion items (used by Central Package Management). | ||
| var versionMap = new System.Collections.Generic.Dictionary<string, string>( | ||
| System.StringComparer.OrdinalIgnoreCase); | ||
| foreach (var v in Versions) | ||
| versionMap[v.ItemSpec] = v.GetMetadata("Version"); | ||
|
|
||
| var sb = new System.Text.StringBuilder(); | ||
| sb.AppendLine("// <auto-generated/>"); | ||
| sb.AppendLine(); | ||
| sb.AppendLine($"namespace {Namespace};"); | ||
| sb.AppendLine(); | ||
| sb.AppendLine("internal static class PackageVersions"); | ||
| sb.AppendLine("{"); | ||
| // Track which packages we've already emitted. | ||
| var emitted = new System.Collections.Generic.HashSet<string>( | ||
| System.StringComparer.OrdinalIgnoreCase); | ||
|
|
||
| foreach (var pkg in Packages) | ||
| { | ||
| var id = pkg.ItemSpec; | ||
|
|
||
| // Prefer Version metadata on the PackageReference itself; fall back to the | ||
| // PackageVersion item (CPM) if not present. | ||
| var version = pkg.GetMetadata("Version"); | ||
| if (string.IsNullOrEmpty(version)) | ||
| versionMap.TryGetValue(id, out version); | ||
| if (string.IsNullOrEmpty(version)) | ||
| continue; | ||
|
|
||
| var propertyName = id.Replace(".", ""); | ||
| sb.AppendLine($" public static string {propertyName} => \"{version}\";"); | ||
| emitted.Add(id); | ||
| } | ||
|
|
||
| // Emit entries for any default packages that weren't already referenced. | ||
| if (Defaults != null) | ||
| { | ||
| foreach (var def in Defaults) | ||
| { | ||
| var id = def.ItemSpec; | ||
| if (emitted.Contains(id)) | ||
| continue; | ||
| var fallback = def.GetMetadata("DefaultVersion"); | ||
| if (string.IsNullOrEmpty(fallback)) | ||
| fallback = "None"; | ||
| var propertyName = id.Replace(".", ""); | ||
| sb.AppendLine($" public static string {propertyName} => \"{fallback}\";"); | ||
| } | ||
| } | ||
| sb.AppendLine("}"); | ||
|
|
||
| var dir = System.IO.Path.GetDirectoryName(OutputFile); | ||
| if (!string.IsNullOrEmpty(dir) && !System.IO.Directory.Exists(dir)) | ||
| System.IO.Directory.CreateDirectory(dir); | ||
| System.IO.File.WriteAllText(OutputFile, sb.ToString()); | ||
| ]]> | ||
| </Code> | ||
| </Task> | ||
| </UsingTask> | ||
|
|
||
| <!-- | ||
| Generate PackageVersions.g.cs before compilation. The target passes both | ||
| PackageReference and PackageVersion items so it works with Central Package | ||
| Management (where Version metadata lives on PackageVersion, not PackageReference). | ||
| --> | ||
| <Target Name="GeneratePackageVersionsFile" | ||
| BeforeTargets="CoreCompile" | ||
| DependsOnTargets="CollectPackageReferences" | ||
| Inputs="$(MSBuildProjectFullPath);$(MSBuildAllProjects)" | ||
| Outputs="$(IntermediateOutputPath)PackageVersions.g.cs"> | ||
| <PropertyGroup> | ||
| <_PackageVersionsFile>$(IntermediateOutputPath)PackageVersions.g.cs</_PackageVersionsFile> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Delete the previously generated file so changes are always picked up. --> | ||
| <Delete Files="$(_PackageVersionsFile)" Condition="Exists('$(_PackageVersionsFile)')" /> | ||
|
|
||
| <ItemGroup> | ||
| <_DefaultPackageVersionEntry Include="Microsoft.Data.SqlClient.Extensions.Azure" DefaultVersion="None" /> | ||
| </ItemGroup> | ||
|
|
||
| <GeneratePackageVersionsClass | ||
| Packages="@(PackageReference)" | ||
| Versions="@(PackageVersion)" | ||
| Defaults="@(_DefaultPackageVersionEntry)" | ||
| Namespace="$(RootNamespace)" | ||
| OutputFile="$(_PackageVersionsFile)" /> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="$(_PackageVersionsFile)" /> | ||
| <FileWrites Include="$(_PackageVersionsFile)" /> | ||
| </ItemGroup> | ||
| </Target> | ||
|
|
||
| </Project> | ||
|
paulmedynski marked this conversation as resolved.
|
This file contains hidden or 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,13 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <packageSources> | ||
| <clear /> | ||
| <add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> | ||
|
|
||
| <!-- | ||
| Add a local directory as a package source. This lets us build against packages that haven't | ||
| been published yet. | ||
| --> | ||
| <add key="local" value="packages/" /> | ||
| </packageSources> | ||
| </configuration> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.