Open maxinfet opened 6 years ago
This workaround should force the use of a response file by temporarily overwriting the TargetFrameworkVersion
. Looking at
and
that shouldn't cause any other problems; lc.exe
itself doesn't seem to need to know the TargetFrameworkVersion.
Add this to your project(s):
<Target Name="WorkaroundMSBuild2836" BeforeTargets="CompileLicxFiles">
<!-- Work around https://github.com/Microsoft/msbuild/issues/2836 by
temporarily setting TargetFrameworkVersion to a version high
high enough to cause the LC task to use a response file. -->
<PropertyGroup>
<_OriginalTargetFrameworkVersion>$(TargetFrameworkVersion)</_OriginalTargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
</Target>
<Target Name="UndoWorkaroundMSBuild2836" AfterTargets="CompileLicxFiles">
<PropertyGroup>
<TargetFrameworkVersion>$(_OriginalTargetFrameworkVersion)</TargetFrameworkVersion>
</PropertyGroup>
</Target>
This same problem affects asp.net core 2.0 apps if the project finds a .licx file, I will try to patch it with the suggested workaround.
Yes it works very well as a work around for asp.net core 2.x apps. I use it for licensing a component, so if I add the nuget package for the component, i add a .targets file in the nuget that will extend MSBuild so that this workaround is applied in any project that uses it, and License Compilation won't fail.
But how did the same work on lower versions of lc.exe without a response file ?
@vijayarag In older versions it never used the response file. It would just fail until you reduced the amount of characters being passed to the command line. The only way to really do this is keep making your path smaller or remove projects from your solution.
@rainersigwald When I first reported this issue I could not find a means to determine what version of LC.exe existed on the machine and what version would be used by Visual Studio. Is there an API that would report this information? The only thing I could figure is to parse the path "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools" which is not a ideal means to determine the tools that are being used.
Thank you so much for this workaround! I have a .net core 2.2 API project that needs an embedded license file and I just could not get by the lc.exe issue. I'm surprised the issue still exists, but.....
I am hitting the same issue today. And while there is a workaround (haven't tested it yet), it would be better to fix it in the tool itself.
Is anyone working on it or is the workaround the accepted solution (in which case I would suggest to close the issue)?
@Kryptos-FR When I looked into this a while ago I could not find an API I could call to get a list of the installed Microsoft SDKs. Since we need at least NETFX 4.6.1 Tools to have a lc.exe that accepts a response file the only "reliable" way I could find to determine my SDK version was to look at the directories available in "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\" and parse the directory name for the version. This is very brittle so I didn't make a pull request for it. If anyone knows of an API in windows that I could call to determine the installed Microsoft SDKs I would make a pull request for this but I never found a means to query that information.
At the company I work at we updated all our solutions to .NET 4.6.1 to get around this instead of using the suggested work around.
Even when lc.exe 4.6.1 is used it will not use the response file unless the project is targeting framework 4.6.1 as well. In issue #1414: the ability to use the response file for lc.exe was limited to 4.6.1 and higher versions of lc.exe. This is being driven by the TargetFrameworkVersion which may not correlate to the actually SdkToolsPath being used.
Steps to reproduce
1.) Create a class library 2.) Set the .Net framework to 4.5 3.) Add a licensed reference and a licenses.licx 4.) Build
Expected behavior
4.6.1 lc.exe would use a response file since the use of the response file it limited by the lc.exe version and not the target framework version.
Actual behavior
4.6.1 lc.exe is used but lc.exe does not use a response file. The command line parameters then get over 32k characters and lc.exe fails and the build fails.
EDIT: added the full output from our build machine.
Environment data
Windows 10.0.16299 Visual Studio 15.5.2