nirin / msbuild-sdks

MSBuild project SDKs
https://nirin.dev/projects/msbuild-sdks
Other
18 stars 2 forks source link

Inference on multi-targeting not working #3

Closed mkaring closed 6 years ago

mkaring commented 6 years ago

Hello,

I noticed that any function that relies on changing the <TargetFramework> property is not working when using multi-targeting.

If you write in the .proj file something like: `net;net-client it should resolve to .NET Framework 4.5 and .NET 4.0 - Client, but it fails all together.

The reason for this is the way MSBuild is called, when using multi targeting. The <MSBuild> gets the TargetFramework using the Properties attribute. It seems this launches MSBuild providing this parameter as command line parameter and those command line parameters can't be simply overwritten.

Nirmal4G commented 6 years ago

Let me look into this...

Just Announced @github + @Microsoft at $7.5B

Nirmal4G commented 6 years ago

I have looked into this, it can be fixed. I'll see what I can do on the NuGet Restore Target side. For now use versioned TargetFramework, i.e. use net45;net40-client instead of net;net-client.

After you fixed your project file, you should see two warnings when you Rebuild:

Warning MSB3267: The primary reference "System.Net.Http", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0,Profile=Client". To resolve this problem, either remove the reference "System.Net.Http" or retarget your application to a framework version which contains "System.Net.Http".

Warning MSB3052: The parameter to the compiler is invalid, '/define:NET40-CLIENT' will be ignored.

You can fix both the warnings by adding these to your project file.

Fix for MSB3267

<ItemGroup>
    <Reference Remove="System.Net.Http">
<ItemGroup>

Fix for MSB3052

<PropertyGroup Condition="$(TargetFramework.EndsWith('-client'))">
    <ImplicitFrameworkDefine>$(TargetFramework.Replace('-','_').ToUpperInvariant())</ImplicitFrameworkDefine>
    <DisableImplicitFrameworkDefines>true</DisableImplicitFrameworkDefines>
</PropertyGroup>
Nirmal4G commented 6 years ago

Will issue a fix later this week along with some planned features: v1.2.0