xenolightning / AudioSwitcher

.NET Library which facilitates interacting with Audio Devices on Windows
Microsoft Public License
248 stars 53 forks source link

Integrate project files into SDK style single project file to simplify project structure, and to be easily packable #54

Closed jsakamoto closed 4 years ago

jsakamoto commented 4 years ago

Hi, Thank you for your great works.

At first, excuse me that I send a pull request including many differences to you without any consultation, any notice.

Motivation

I want to use this library on my .NET Core 3.1 application by package referencing from nuget.org.

However, those NuGet packages that I can get from the above URL doesn't contain a binary suitable for the .NET Core app. It just only contains binaries for .NET Framework 4.0 and .NET Framework 4.5.

I was searching inside of your GitHub repository, and I found that the repository contains the .NET Standard edition project file. I found also .nuspec files are there, but those .nuspec files don't contain descriptions of .NET Standard edition binary files.

So I want to help you to publish a newer version of these libraries that contain .NET Standard edition binaries, therefore I decided to send this pull request for you.

Technical Background

Recently, we can use an "SDK style" project file to developing any C# programming even though class libraries.

May be already you know, an SDK style project file allows us to make multi-targeting frameworks class library easier.

We have to do that is just listing the target framework's TFM (Target Framework Moniker) inside a <TargetFrameworks> element in a project file, like this.

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

And, an SDK style project file also allows us to create a NuGet package file without .nuspec file.

I used these technics, I succeeded that updating these libraries' projects to include not only .NET4.0 and 4.5 but also .NET Standard. Furthermore, those project files can be creatable a NuGet package by a single click on VisualStudio GUI.

Before and after of this pull request

By using the "SDK style" project file, I integrated many project files (Shared project file, and project files for each of frameworks) and nuspec file into a single "SDK style" project file.

fig.1 Before
image

fig.2 After
image

I applyed this change to AudioSwitcher.AudioApi and AudioSwitcher.AudioApi.CoreAudio.
(I didn't apply this change to AudioSwitcher.Scripting.JavaScript.)

To create a NuGet package on Visual Studio, right-click the project in solution explorer window to open a context menu, and just click [Pack] menu item in the context menu.

fig.3 Manipulating Visual Studio to create the NuGet package
image

After click [Pack] menu item, a NuGet package file will be generated in the output folder. (such as "./bin/Debug", "./bin/Relese")

fig.4 The output folder and the generated NuGet package file
image

The internal structure of the generated NuGet package file includes binaries for each target framework and includes information of dependencies for each target framework.

fig.5 Showing the internal structure of the generated NuGet package via "NuGet package Explorer"
image

To change the version number of the NuGet package, open .csproj file in an editor and edit the value of <Version> element.

fig.6 Editing the package version in the .csproj file
image

I didn't touch any C# source codes, so all unit test cases were passed after these project structure's changes.

fig.7 The results of unit testing
image

Important Notice

I couldn't build with the "Release" configuration due to I don't have the credential information for using "api.pfx".

Severity    Code    Description Project File    Line    Suppression State
Error   MSB3325 Cannot import the following key file: api.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_0FC604BA773FF5A5   AudioSwitcher.AudioApi  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 3203    
Error   MSB3321 Importing key file "api.pfx" was canceled.  AudioSwitcher.AudioApi  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 3203    

fig.8 A screen shot of build errors list
image

Conclusion

I can imagine that you will surprise due to receive a many-change lines pull request. But I hope please don't be afraid it because quite a few changes in this pull request is just changing project reference, like from "AudioSwitcher.AudioApi (NETStandard2.0).csproj" to "AudioSwitcher.AudioApi.csproj".

I will not mind if this pull request is rejected if the NuGet package becomes including .NET Standard binary in another way.
Because I hope that you and everyone who are .NET Core app developers become happy by the NuGet packages will include .NET Standard binary, regardless of how or who is implemented.

Anyway, thank you for your great works, and thank you for reading this long pull request message form me.

xenolightning commented 4 years ago

Looks really good!

I'll check out the branch and do a bit of a sanity check - but I think everything is in order 👍

jsakamoto commented 4 years ago

I'm appreciating spending your time on this pull request! And thanks once more for your great works!

xenolightning commented 4 years ago

I had a few issues running tests - but that was more to do with the dev machine I was working on at the time.

It all looks good as is - will merge.

Thanks for the PR, and all related information 👍