Either include a project sample, attach a zipped project, or provide IDE / CLI steps to create the project and repro the behaviour. Example of a project sample:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<Target Name="_ComputeAssemblyInfoAttributes"
BeforeTargets="GetAssemblyAttributes">
<ItemGroup>
<AssemblyAttribute Include="System.CLSCompliant">
<_Parameter1>true</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute">
<_Parameter1>System.Runtime.InteropServices.DllImportSearchPath.AssemblyDirectory | System.Runtime.InteropServices.DllImportSearchPath.System32</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Target>
</Project>
dotnet build
Expected behavior
A successful build with the CLSCompliant and DefaultDllImportSearchPaths assembly attributes applied correctly.
Actual behavior
The generated code can't compile:
[assembly: System.CLSCompliant("true")]
[assembly: System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute("System.Runtime.InteropServices.DllImportSearchPath.AssemblyDirectory | System.Run" +
"time.InteropServices.DllImportSearchPath.System32")]
obj\Debug\netstandard2.0\MSBuildBug.AssemblyInfo.cs(10,32): error CS1503: Argument 1: cannot convert from 'string' to 'bool' [F:\DotNetTest\MSBuildBug\MSBuildBug.csproj]
obj\Debug\netstandard2.0\MSBuildBug.AssemblyInfo.cs(11,80): error CS1503: Argument 1: cannot convert from 'string' to 'System.Runtime.InteropServices.DllImportSearchPath' [F:\DotNetTest\MSBuildBug\MSBuildBug.csproj]
Environment data
msbuild /version
output:
OS info:
If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc):
dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.1.300
Commit: adab45bf0c
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.300\
Yea, looks like a dupe . Maybe @AndyGerlicher would reconsider re-opening #2281.
My scenario is a bit more complicated than normal, and more complicated than described above. I'm converting dotnet/corefx to use SDK projects. We currently have our own GenerateAssemblyInfo target in dotnet/buildtools. And we build a lot of different kinds of assemblies in the repo (ref assemblies, facades, netfx, uap, netstandard, netcoreapp, etc). The rules for when to apply CLSCompliant
, ComVisible
, DefaultDllImportSearchPathsAttribute
, and AssemblyFlags
attributes to an assembly aren't always simple, and are best kept in a centralized place.
For now, I've opted to use the SDK's GenerateAssemblyInfo target when possible. But for the attributes that require non-strings, I write an extra AssemblyInfo file.
I have felt your pain @eerhardt. I've had many similar complexities in building multi-target libraries. IMHO, your scenario is not all the complicated at all and is completely reasonable to me. The solution to this problem isn't all that hard to implement either. We just need a way to tell MSBuild to use the input we provide verbatim without any escaping. If it's wrong, it's on us - the authors. As @dasMulli has proven, this capability could be shipped in an hour and make the rest of our lives a lot easier. I'm not sure why there is so much resistance to such a simple change that has obvious benefit.