hi, not sure if this is the correct place to chat
So I am fixing my project to compile for both VS 4 Mac/VS 4 Windows
At the moment got most projects compiling with
<TargetFrameworks>netstandard2.0;net461;uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10;MonoAndroid81;netcoreapp2.0;tizen40</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard2.0;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10;MonoAndroid81;netcoreapp2.0;tizen40</TargetFrameworks>
So for non windows I exclude net461/uap (using MsBuild.Sdk.Extras btw hence the extra TargetFrameworks.
My question is how can I exclude a project from compiling altogether for a non-windows build. Eg I got a uap/net461 only project. Can I do the condition on the project level? I know I could take the approach of a separate .sln file but that's a last resort for me
also another question I have is I am a bit confused by the relationship of the .net SDK and msbuild
Eg to get LicenseExpression tag working I need to have installed .net core 2.1 onwards, even though my project is targetting netcoreapp2.0
Does the .net sdk provide some sort of templates for msbuild?
to disable compilation, you can try something like conditionally importing a targets file (in Directory.Build.targets
), for example DisableTargets.targets
, and then overriding default build targets, something like this:Directory.Build.targets
:
...
<Import Project="DisableTargets.targets" Condition="'$(DisableTargets)' == 'true'" />
...
DisableTargets.targets
:
<Project>
<Target Name="Build" />
</Project>
<TargetFrameworks>netstandard2.0;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10;MonoAndroid81;netcoreapp2.0;tizen40</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net461;uap10.0.16299</TargetFrameworks>
I am considering doing like
<Import Project="DisableTargets.targets" Condition="'$(TargetFramework.StartsWith('net4')) and '$(OS)' != 'Windows_NT'" />
In my Directory.Build.Targets
some
We use the target frameworks to include different directories in our platform folder
<ItemGroup>
<Compile Remove="Platforms\**\*.cs" />
<None Include="Platforms\**\*.cs" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('netstandard')) ">
<Compile Include="Platforms\netstandard2.0\**\*.cs" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
<Compile Include="Platforms\net461\**\*.cs" />
</ItemGroup>
So it gets isolated off
Using Workspace As MSBuildWorkspace = MSBuildWorkspace.Create()
Dim currentProject As Project = Workspace.OpenProjectAsync(FileName).Result
Workspace.LoadMetadataForReferencedProjects = True
If currentProject.HasDocuments Then
For Each document As Document In currentProject.Documents
The expression "[Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries(_, net35, '', '', '', '')" cannot be evaluated. Version string portion was too short or too long.