-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Projects don't work with dotnet CLI tooling #1
Comments
@mmiller678 Because this is targeting net4x and requires the WebApplication targets file from Visual Studio (available by installing the ASP.Net 4.x workload) I don't think you will be able to build using dotnet build. I think you will need to use a build server with VS2019 Build Tools installed and build using MSBuild instead. The only alternative would be to include the contents of C:\Program Files (x86)\Microsoft Visual Studio\2019\xxxx\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications in the NuGet package next to the SDK files. These are copyright Microsoft and part of Visual Studio so I cannot include them. If it were allowed, it would mean you wouldn't need to install the ASP.NET 4.x workload though. I'm not entirely sure what the issue with I did look at adding the The ASPNET Compiler is only needed if you want/need to precompile your markup files. In general I would recommend using this as a 'head' project and moving MVC views into a class library and using the excellent RazorGenerator.Mvc package along with the RazorGenerator.MsBuild package to compile the views into your class libraries avoiding the need for the Perhaps I need to clarify the documentation about using and building inside and outside VS. |
@mmiller678 mkdir test
cd test
dotnet new systemwebfull
dotnet build -p:"VSToolsPath=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VisualStudio\v16.0" It fails with mkdir test2
dotnet new systemwebfull
msbuild
msbuild /t:Publish /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingeFile=true /p:PackageLocation="MyPublishDir" succeeds from a VS2019 developer command prompt. |
Forgive me for trying to re-open a closed by design/wontfix issue, but I believe an improvement can be made without any drawbacks. While there are several reasons to continue to build with The dotnet tools do not work because the sdks do not include However, updating the import to this:
Would allow the directory to be overridden in the csproj:
FYI: |
@FuncLun Unfortunately, even adding the .targets files etc. to the SDK won't work, as some of those targets use features that only work in MSBuild, and not under dotnet as they require .NETFramework tasks which are not compatible with .NETCore which is used when you try and run it under dotnet. If you look at e.g. the VSSDK for Visual Studio Extensions nuget package you can see they basically do what you are talking about. That package includes the targets, and DLLs that would normally be installed with visual studio, so that you can compile on a build server which doesn't have the VSSDK workload installed. <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="VSSDK_NuGet_Configuration">
<ThisPackageDirectory>$(MSBuildThisFileDirectory)..\</ThisPackageDirectory>
<VSToolsPath>$(ThisPackageDirectory)\tools</VSToolsPath>
<VsSDKInstall>$(VSToolsPath)\VSSDK</VsSDKInstall>
<VsSDKIncludes>$(VsSDKInstall)\inc</VsSDKIncludes>
<VsSDKToolsPath>$(VsSDKInstall)\bin</VsSDKToolsPath>
</PropertyGroup>
</Project> Unfortunately, there isn't an equivalent Microsoft.WebApplications.BuildTools type of package - and I believe the targets files and associated custom tasks and DLLs are copyrighted as part of VS and not public domain, and are not part of the redistributables allowed by the licence. One solution to mixing dotnet pack -c Debug.Pack It is perfectly possible to use msbuild /t:pack instead of dotnet pack anyway. Alternatively, I suggest you use multiple solution files, one of which only contains projects that work with dotnet if you cannot work with msbuild. Also, you can simply add the nuget package NuGet.Build.Tasks.Pack if you want to enable the pack target for a web application project. <PackageReference Include="NuGet.Build.Tasks.Pack" Version="5.10.0" /> You can then prevent it actually packing the project by adding the property <IsPackable>false</IsPackable> dotnet pack -p:"VSToolsPath=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VisualStudio\v16.0"
|
@FuncLun A quick follow up - I found another unofficial nuget package which I think includes the VS2015 versions of the web.application.targets and associated files. <PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="5.10.0" />
<PackageReference Include="MSBuild.Microsoft.VisualStudio.Web.targets" Version="14.0.0.3" Condition="'$(MSBuildRuntimeType)' == 'Core'"/>
</ItemGroup> |
If your goal is building the app on a CI server without Visual Studio you can install the same workload from Build Tools: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019 |
@CZEMacLeod does it make sense to mark this issue with the |
@julealgon It is tagged as |
Fair enough, thanks for elaborating @CZEMacLeod 😉 I'll probably pursue this on my own later because being able to unify our build pipelines using the |
I believe this still can be resolved by finding VS installation and importing the web targets from there. <Project>
<ItemGroup>
<PackageReference Include="vswhere" GeneratePathProperty="true" />
</ItemGroup>
<Target Name="FindWebApplicationTargets">
<PropertyGroup>
<VSWherePath>$([MSBuild]::NormalizePath('$(Pkgvswhere)', 'tools'))</VSWherePath>
</PropertyGroup>
<!-- Work out VS installation path, so we can find MSBuild.exe -->
<Exec
Command="vswhere.exe -latest -prerelease -property installationPath -requires Microsoft.VisualStudio.Component.Web"
WorkingDirectory="$(VSWherePath)"
EchoOff="true"
ConsoleToMsBuild="true"
StandardOutputImportance="Low">
<Output TaskParameter="ConsoleOutput" PropertyName="_VSInstallPath" />
</Exec>
<Error Text="Unable to find Visual Studio installation." Condition="!Exists($(_VSInstallPath))" />
<PropertyGroup>
<_MSBuildVsPath>$([MSBuild]::NormalizePath('$(_VSInstallPath)', 'MSBuild', 'Microsoft', 'VisualStudio'))</_MSBuildVsPath>
</PropertyGroup>
<ItemGroup>
<_WebTargets Include="$(_MSBuildVsPath)\**\WebApplications\Microsoft.WebApplication.targets" />
</ItemGroup>
<Error Text="Unable to locate $(_MSBuildVsPath)\<version>\WebApplications\Microsoft.WebApplication.targets. Ensure Microsoft.VisualStudio.Component.Web workload is installed."
Condition="@(_WebTargets->Count()) != 1"/>
<PropertyGroup>
<_WebApplicationTargetsPath>@(_WebTargets)</_WebApplicationTargetsPath>
</PropertyGroup>
<Message Text="Microsoft.WebApplication.targets: $(_WebApplicationTargetsPath)" Importance="High" />
</Target> I assume "Microsoft.VisualStudio.Component.Web" workload is responsible for Microsoft.WebApplication.targets file but I'm not 100% sure. |
@RussKie Thanks for that idea - it might be able to resolve the path to the dll, but I think there is still the problem that those DLLs refer to I'd be willing to add the extra code in (or accept a PR) if it actually enables any usable scenarios. |
The scenario is the ability to build the solution with I'm currently "lucky" to work on an old solution which consists of a mix of .NET Framework, .NET Standard and .NET projects. Unless I convert the lot to the SDK-style I can't use
Setting en envvar may work for a single dev, however, in a distributed environment it won't scale - i.e., every contributor to the repo will have to know to set the variable in order to build from cli.
IMO this is a weak argument. Look at how many NuGet packages a typical restore pulls in, one more or one less won't make a difference, however it delivers a significant devex benefit. |
@RussKie Fair enough on the comment about assuming what developers use. I was more meaning in the context of someone working with a legacy project including aspnet4, which is based on an msbuild / windows / visual studio ecosystem, trying to use tools designed for a different runtime (netcore/dotnet) is IMHO not the majority use case. The point of this SDK is to allow the use of an SDK style csproj file and its benefits - globbing, easy diffing, edit in place, etc. Being able to compile using As for the weight - true enough, but pulling in something that is only used in one scenario, which isn't really supported anyway, seems to be a bad decision - and adding the logic to detect building outside of Visual Studio (either in the IDE or via the command line) affects the performance for everyone. I will admit that performance isn't really a goal of this SDK either, but making the overall system slower when it isn't needed seems to be a mistake. Now on the particular issue with I would suggest that if you are happy using cli tools, that you create an appropriate build script file, running As mentioned further back, using tools designed for netcore to build a net4 project is not a goal of this project. |
@RussKie If you come up with a clean solution with minimal impact to the existing build system, please open a PR and we can go from there. |
Hi,
Great job on putting these together. I have using SDK projects for our .NET 4.8 projects but had some issues with our MVC projects. With the help from the work you have done plus the long running thread on .NET project system site (dotnet/project-system#2670) I was able to get most of it going. One issue I did run into is while trying to implement MvcBuildViews support to run the dotnet tooling for use on our build server. While your projects do work in the Visual Studio they fail to work from dotnet cmd line tools.
dotnet build for instance results in:
C:\Users\xxx.nuget\packages\msbuild.sdk.systemweb\4.0.33\Sdk\Sdk.targets(16,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\5.0.201\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\5.0.201\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" is correct, and that the file exists on disk. [c:\Users\xxx\Downloads\MSBuild.SDK.SystemWeb-main\MSBuild.SDK.SystemWeb-main\samples\ExampleEmptyWebApplication\ExampleEmptyWebApplication.csproj]
Build FAILED.
If I remove this property group:
The problem is resolved. Any ideas on how to get this working from the cmd line?
The text was updated successfully, but these errors were encountered: