I am having an issue getting MSBuild to compile c# 6.0 code, it reports a failure when trying to build expression body syntax, etx.
So I've been creating build project like this for years. I have a powershell script that kicks of an msbuild with some parameters:
msbuild.exe _build\build.proj
/p:Build_Number=1.2.0
/p:Configuration=QA
/p:SolutionName=MPGCS-Api.sln
/ToolsVersion:14.0
I verified that msbuild.exe is coming from C:\Program Files (x86)\MSBuild\14.0\Bin , i did this by going into that folder and specifying the full physical path to the .proj file. I get the same exact errors.
I have been looking for an example on how to setup a MSBuild project file with C# 6.0 with no luck, so this is my basic setup (this is the build.proj file). If I had to guess I am not importing the correct targets, etc. But I am a little lost. Here is my proj file:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Root>$(MSBuildStartupDirectory)</Root>
<NugetExe>$(Root)\_build\lib\nuget\nuget.exe</NugetExe>
<Build_Number>0.0.0</Build_Number>
<SolutionName></SolutionName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Target Name="Clean">
<!-- Clean up -->
<ItemGroup>
<FilesToDelete Include="$(Root)\_build\Artifacts\**\*.*" />
<FilesToDelete Include="$(Root)\_build\Published\**\*.*" />
</ItemGroup>
<Delete Files="#(FilesToDelete)" ContinueOnError="false" />
<!-- Ensure directories exists -->
<MakeDir Directories="$(MSBuildProjectDirectory)\Artifacts" Condition="!Exists('$(MSBuildProjectDirectory)\Artifacts')" />
<MakeDir Directories="$(MSBuildProjectDirectory)\Published" Condition="!Exists('$(MSBuildProjectDirectory)\Artifacts')" />
</Target>
<Target Name="Debug" AfterTargets="Clean">
<!-- Diagnostics -->
<Message Text="Diagnostics:"/>
<Message Text="Build Number: $(build_number)" />
<Message Text="Configuration: $(Configuration)" />
<Message Text="VisualStudioVersion: $(VisualStudioVersion)" />
<Message Text="Project root: $(Root)" />
<!-- Restore Nuget Packages -->
<Message Text="Restoring nuget..."/>
<Exec Command="$(NugetExe) restore $(Root)\$(SolutionName)" />
</Target>
<Target Name="GenerateOctopackAPI" AfterTargets="Debug">
<ItemGroup>
<ProjectToBuild Include="$(Root)\MPG.CS.Api\MPG.CS.Api.csproj" />
</ItemGroup>
<MSBuild Projects="#(ProjectToBuild)" ContinueOnError="false" Targets="Rebuild" Properties="
RunOctoPack=true;
Configuration=$(ProjectBuildMode);
Platform=AnyCpu;
TargetFrameworkVersion=$(TargetFrameworkVersion);
VisualStudioVersion=$(VisualStudioVersion);
OctoPackPublishPackageToFileShare=$(Root)\_build\Artifacts;
OctoPackPackageVersion=$(Build_Number);
OctoPackProjectName=UI;
OutputPath=bin\$(ProjectBuildMode)" />
</Target>
</Project>
Here is some info from my "Debug" target, as you can see I am setting the VisualStudioVersion to 14.0 as per some suggestions I read online.
Diagnostics:
Build Number: 1.2.0
Configuration: QA
VisualStudioVersion: 14.0
Project root: C:\dev\mpg\MPGCS-Api
Here is an example error, it's basically failing on c# 6.0 code, if I were to remove c# 6 code, everything will compile:
TicketType.cs(19,28): error CS1002: ; expected [C:\dev\mpg\MPGCS-Api\MPG.CS.Model\MPG.CS.Model.csproj]
TicketType.cs(19,44): error CS1519: Invalid token '(' in class, struct, or interface member declaration [C:\dev\mpg\MPGCS-Api\MPG.CS.Model\MPG.CS.Model.cs proj]
TicketStatus.cs(16,36): error CS1002: ; expected [C:\dev\mpg\MPGCS-Api\MPG.CS.Model\MPG.CS.Model.csproj]
TicketStatus.cs(16,53): error CS1519: Invalid token '(' in class, struct, or interface member declaration [C:\dev\mpg\MPGCS-Api\MPG.CS.Model\MPG.CS.Model. csproj]
TicketStatus.cs(16,82): error CS1519: Invalid token '(' in class, struct, or interface member declaration [C:\dev\mpg\MPGCS-Api\MPG.CS.Model\MPG.CS.Model. csproj]
Here is a line it's failing on (C# 6 code):
public bool IsAbbreviated => (Title.ToLower() == "open" || Title.ToLower() == "closed");
I'm at a loss, I thought just using the proper msbuild.exe will allow me to take advantage of c# 6.0. Any help would be greatly appreciated.
If you're running the powershell script on a build server, separate from your dev environment, you will need to make sure that the machine itself can handle C# 6.0. Since it uses a different compiler all together, it wouldn't work if VS 2015 wasn't installed. Alternately, you can add the Microsoft.Net.Compilers nuget package as a dependency to allow VS 2012 and VS 2013 to compile it.
Related
I am following Get started with Blazor. I have created the application and attempt to run it as is i have made no changes.
There are three things in my event log.
The directory specified for caching compressed content C:\inetpub\temp\IIS Temporary Compressed Files\Clr4IntegratedAppPool is invalid. Static compression is being disabled.
Application 'MACHINE/WEBROOT/APPHOST/WEBAPPLICATION1' with physical root 'C:\Users\LindaL\source\repos\Daimto.RazorTest.Tools\WebApplication1\' failed to start process with commandline 'c:\program files (x86)\microsoft visual studio\2017\professional\common7\ide\extensions\microsoft\web tools\projectsystem\VSIISExeLauncher.exe -argFile "C:\Users\LindaL\AppData\Local\Temp\tmpF272.tmp"', ErrorCode = '0x80004005' : 0.
Application 'MACHINE/WEBROOT/APPHOST/WEBAPPLICATION1' with physical root 'C:\Users\LindaL\source\repos\Daimto.RazorTest.Tools\WebApplication1\' failed to start process with commandline 'c:\program files (x86)\microsoft visual studio\2017\professional\common7\ide\extensions\microsoft\web tools\projectsystem\VSIISExeLauncher.exe -argFile "C:\Users\LindaL\AppData\Local\Temp\tmpF272.tmp"', ErrorCode = '0x80004005' : 0.
Note i just update to visual studio professional 2017 15.9.3. I have used blazor before this was working fine.
Update: This appears only in the "Blazor" project type.
Update2: hitting Cntrl-F5 as opposed to just F5 – No change.
Update3 Project file per request in comment in answer below
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RunCommand>dotnet</RunCommand>
<RunArguments>blazor serve</RunArguments>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="0.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.6.0" PrivateAssets="all" />
<DotNetCliToolReference Include="Microsoft.AspNetCore.Blazor.Cli" Version="0.6.0" />
</ItemGroup>
</Project>
Delete global.json and see if that helps.
https://github.com/aspnet/Blazor/issues/1342
If that doesn't help try adding global.json with content
{
"sdk": {
"version": "2.1.500"
}
}
If all fails, close all Visual Studio instances and reinstall Blazor templates with dotnet new -i Microsoft.AspNetCore.Blazor.Templates and create new Blazor solution with dotnet new and use Blazor template you want.
I have following projects on solution and this works perfectly fine on my local.
However when I check code in Team service and create build it fails.
mainconsole.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PackageTargetFallback>portable-net45+win8</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.Portable.Compatibility" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\business\business.csproj" />
<ProjectReference Include="..\portableextensibility\portableextensibility.csproj" />
<ProjectReference Include="..\portablelibrary\portablelibrary.csproj" />
</ItemGroup>
</Project>
Build tasks:
command line - tool dotnet, argument - restore
command line - tool dotnet, argument - build
Build fails:
d:\a\3\s\portablelibrary\portablelibrary.csproj(43,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\1.0.4\Microsoft\Portable\v4.5\Microsoft.Portable.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
d:\a\3\s\portableextensibility\portableextensibility.csproj(42,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\1.0.4\Microsoft\Portable\v4.5\Microsoft.Portable.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): error : Unable to resolve 'd:\a\3\s\portableextensibility\portableextensibility.csproj' for '.NETCoreApp,Version=v1.1'. [d:\a\3\s\dotnetcompatibility.sln] C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): error : Unable to resolve 'd:\a\3\s\portablelibrary\portablelibrary.csproj' for '.NETCoreApp,Version=v1.1'. [d:\a\3\s\dotnetcompatibility.sln] Generating MSBuild file d:\a\3\s\mainconsole\obj\mainconsole.csproj.nuget.g.props. Generating MSBuild file d:\a\3\s\mainconsole\obj\mainconsole.csproj.nuget.g.targets. Writing lock file to disk. Path: d:\a\3\s\mainconsole\obj\project.assets.json Restore failed in 37.7 sec for d:\a\3\s\mainconsole\mainconsole.csproj.
Errors in d:\a\3\s\business\business.csproj
Unable to resolve 'd:\a\3\s\portablelibrary\portablelibrary.csproj' for '.NETStandard,Version=v1.1'.
Errors in d:\a\3\s\mainconsole\mainconsole.csproj
Unable to resolve 'd:\a\3\s\portableextensibility\portableextensibility.csproj' for '.NETCoreApp,Version=v1.1'.
Unable to resolve 'd:\a\3\s\portablelibrary\portablelibrary.csproj' for '.NETCoreApp,Version=v1.1'.
Since the solution contains PCL libraries which currently cannot be built using the dotnet cli, the project has to be built through msbuild instead of the dotnet based commands.
Here is the corrected configuration:
Build Definition
Queue options
Result
I am currently working on a project in C#, and trying to get NUnit to run on my project in a Jenkins Build through restoring the package in NuGet. We do not want to install NUnit on all of our Jenkins machines so installing it directly on the box is not an option.
We've investigated the use of NUniter Runners as suggested in this link: https://peteris.rocks/blog/running-nunit-with-msbuild-on-windows-and-mono/
But, we receive an error that the tools do not exist
"C:\Users\Name\NewBranch\project\project.Tests\project.Tests.csproj(121,3): error MSB6003
: The specified task executable "cmd.exe" could not be run. The working directory "C:\Users\Name\NewBranch\project\
packages\NUnit.Runners.3.4.1\tools" does not exist."
How do I execute NUnit tests from the command line without having NUnit installed directly on the machine?
the easiest way is to dump there 2 lines in the packages.config which should be in the same folder as your project.Tests.csproj
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="NUnit.Runners" version="2.6.4" />
Assuming you have a target in your .csproj which is like this:
<Target Name="NugetRestore">
<Exec Command="nuget.exe restore" />
</Target>
if you use a solution level build.config, then add this instead
<Target Name="NugetRestore">
<Exec Command="nuget.exe restore $(YourSolution).sln" />
</Target>
I have a cloud project with two web roles set up in a directory structure like this :
C:\myWork\myProject\
Solution.sln
\CloudService\CloudService.ccproj
\WebRole1\WebRole1.csproj
\WebRole2\WebRole2.csproj
My cloud service .csdef is :
<ServiceDefinition name="CloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6">
<WebRole name="WebRole1" vmsize="Small">
<Sites>
<Site name="WebRole1"
physicalDirectory="..\..\..\WebRole1\publish\_PublishedWebsites\WebRole1">
<Bindings>
<Binding name="http"
endpointName="http"
hostHeader="WebRole1.cloudapp.net" />
</Bindings>
</Site>
<Site name="WebRole2"
physicalDirectory="..\..\..\WebRole2\publish\_PublishedWebsites\WebRole2">
<Bindings>
<Binding name="http"
endpointName="http"
hostHeader="WebRole2.cloudapp.net" />
</Bindings>
</Site>
</Sites>
-snip-
When I package the CloudService project in VS2015, the package creates fine with both WebRoles built and within the package as expected. It uploads to Azure and both WebRoles are active and error free.
However, if I build with MSBuild through the command line :
msbuild /t:corepublish;package /p:visualstudioversion=14.0;targetframeworkversion=4.5;roletargetframework=4.5;config
uration=debug
I receive the following error during CorePublish :
CorePublish:
CorePublish: PackageWebRole = True
Publishing starting...
RolePlugins is
Importedmodules is
Publishing to 'Publishapp.publish\'
Creating directory "Publishapp.publish\".
TargetServiceDefinition is Publish\ServiceDefinition.csdef
TargetServiceConfiguration is Publish\ServiceConfiguration.cscfg
Roles is
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Windows Azure Tools\2.6\Microsoft.WindowsAzure.targets(3003,5): warning : CloudServices68 : No TargetFrameworkVersion specified for role WebRole1. Using .NET framework v4.0 for packaging. [c:\mywork\myproject\CloudService\CloudService.ccproj]
c:\mywork\myproject\CloudService\Publish\ServiceDefinition.csdef : error CloudServices079: Cannot find the physical directory 'c:\mywork\WebRole1\publish\_PublishedWebsites\WebRole1' for virtual path WebRole1/. [c:\mywork\myproject\CloudService\CloudService.ccproj]
Done Building Project "c:\mywork\myproject\CloudService\CloudService.ccproj" (Publish target(s)) -- FAILED.
Done Building Project "c:\mywork\myproject\Solution.sln" (Rebuild;Publish target(s)) -- FAILED.
Done Building Project "c:\mywork\myproject\cloudservice\cloudservice.ccproj" (corepublish;package target(s)) -- FAILED.
As you can see, MSBuild is looking for WebRole1 here : c:\mywork\WebRole1 whereas it should be looking here : c:\mywork\myproject\WebRole1.
So why is packaging the cloud service working inside VS2015, yet not with MSBuild ?
I had a very similar issue, and in my case I had to update the MyProject.Azure.ccproj file so that it was always prefixing the PublishPath with the $(ProjectDir). It was not doing that for TFS build originally. I made them the same for now. Not entirely sure if the example I got here is even relevant anymore.
Before:
<PropertyGroup Condition=" '$(PublishDestinationPath)'=='' and '$(BuildingInsideVisualStudio)'=='true' ">
<!-- When Visual Studio build -->
<PublishDestinationPath>$(ProjectDir)$(OutDir)</PublishDestinationPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(PublishDestinationPath)'=='' ">
<!-- When TFS build -->
<PublishDestinationPath>$(OutDir)</PublishDestinationPath>
</PropertyGroup>
After:
<PropertyGroup Condition=" '$(PublishDestinationPath)'=='' and '$(BuildingInsideVisualStudio)'=='true' ">
<!-- When Visual Studio build -->
<PublishDestinationPath>$(ProjectDir)$(OutDir)</PublishDestinationPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(PublishDestinationPath)'=='' ">
<!-- When TFS build -->
<PublishDestinationPath>$(ProjectDir)$(OutDir)</PublishDestinationPath>**
</PropertyGroup>
I have a solution with a Windows Azure Cloud Services project, that compiles fine from VS and command line.
If I try to make a package, it works fine from VS, but fails from command line.
Here is my command line from Powershell:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe .\project.sln --%
/p:Configuration="QA" /p:TargetProfile="CloudQA" /p:Platform="Any CPU" /target:Publish
/nr:false
I have this error:
"C:\CI\project\project.sln" (Publish target) (1) ->
"C:\CI\project\WindowsAzure\WindowsAzure.ccproj.metaproj" (Publish target) (11) ->
"C:\CI\project\WindowsAzure\WindowsAzure.ccproj" (Publish target) (12) ->
(PrepareRoleItems target) ->
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Windows Azure Tools\2.0\Microsoft.WindowsAzure.targets(13
02,5): error MSB4096: The item "C:\CI\project\project.WebAPI\project.WebAPI.csproj" in item list "Projec
tReferenceWithConfiguration" does not define a value for metadata "Name". In order to use this metadata, either qualif
y it by specifying %(ProjectReferenceWithConfiguration.Name), or ensure that all items in this list define a value for
this metadata. [C:\CI\project\WindowsAzure\WindowsAzure.ccproj]
EDIT
Few interesting things:
Here is my csdef file
<WorkerRole name="ProjectWorker" vmsize="ExtraSmall">
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<Endpoints>
<InternalEndpoint name="InternalEndpoint1" protocol="http" />
</Endpoints>
<ConfigurationSettings>
</ConfigurationSettings>
</WorkerRole>
<WebRole name="Project.Web" vmsize="ExtraSmall">
<Sites>
<Site name="Web">
<Bindings>
<Binding name="http" endpointName="http" />
</Bindings>
</Site>
<Site name="Api" physicalDirectory="..\..\..\Project.WebAPI">
<Bindings>
<Binding name="http" endpointName="http81" />
</Bindings>
</Site>
</Sites>
<Endpoints>
<InputEndpoint name="http" protocol="http" port="80" />
<InputEndpoint name="http81" protocol="http" port="81" />
</Endpoints>
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
</WebRole>
As you can see, I have two websites on one WebRole.
Now, let's have a look at the ccproj file:
<ItemGroup>
<ProjectReference Include="..\Project.Web\Project.Web.csproj">
<Name>Project.Web</Name>
<Project>{5d000123-0000-4b6e-b5fa-72525afca7f5}</Project>
<Private>True</Private>
<RoleType>Web</RoleType>
<RoleName>Project.Web</RoleName>
<UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
</ProjectReference>
<ProjectReference Include="..\ProjectWorker\ProjectWorker.csproj">
<Name>ProjectWorker</Name>
<Project>{22e99999-1000-4559-8507-a948b7e3d1b0}</Project>
<Private>True</Private>
<RoleType>Worker</RoleType>
<RoleName>ProjectWorker</RoleName>
<UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
</ProjectReference>
</ItemGroup>
Only two projects are referenced in the ccproj instead of 3.
The cloud project has 3 dependencies in the sln.
If I had a reference by hand in the ccproj like this:
<ProjectReference Include="..\Project.WebAPI\Project.WebAPI.csproj">
<Name>Project.Web</Name>
<Project>{A0F88888-3333-4823-A34F-5F01F0A3FFFF}</Project>
<Private>True</Private>
<RoleType>Web</RoleType>
<RoleName>Project.WebAPI</RoleName>
<UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
</ProjectReference>
I have this error:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Windows Azure Tools\2.0
\Microsoft.WindowsAzure.targets(987,5): error : CloudServices25 : Multiple directories are
specified for role Project.Web. [C:\CI\project\WindowsAzure\WindowsAzure.ccproj]
Now if I update the reference like this:
<ProjectReference Include="..\Project.WebAPI\Project.WebAPI.csproj">
<Name>Project.WebAPI</Name>
<Project>{A0F88888-3333-4823-A34F-5F01F0A3FFFF}</Project>
<Private>True</Private>
<RoleType>Web</RoleType>
<RoleName>Project.Web</RoleName>
<UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
</ProjectReference>
I have this error:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Windows Azure Tools\2.0
\Microsoft.WindowsAzure.targets(987,5): error : CloudServices26 : Cannot find role
named 'Project.WebAPI' in service description file
C:\CI\project\WindowsAzure\bin\UAT\ServiceDefinition.csdef.
[C:\CI\project\WindowsAzure\WindowsAzure.ccproj]
I found this link: Visual Studio 2010 Beta 2 myTODO Error message it works for me. The valuable information from that link:
It seems like maybe Azure does not like it if you specify anything besides an Azure Role project as a dependency on the service project. I made it so MyWebRole.csproj was dependent on xxx.csproj, instead of MyService.ccproj being dependent on xxx.csproj, and it worked.
This post solved my problem:
http://michaelcollier.wordpress.com/2013/01/14/multiple-sites-in-a-web-role/
A must read if you have several websites on one webrole!
I stumbled upon a similar problem when building my cloud project from the command line, in particular I get this exception if the web project referenced by the VirtualDirectory tag is marked as a build dependency for the cloud project.
To avoid this and ensure that the web project is compiled and included in the cspack, I come up with a procedure simpler that the one cited in Swell's answer -- in particular it does not require to alter the project files but only to call two targets in a precise order:
ensure in Configuration Manager that the web project will be rebuilt in the desired solution configuration (for example ensure that it is built under Release configuration);
ensure that the web project is not a build dependency of the cloud project;
do a rebuild of the solution, for example
MsBuild solution.sln /t:Rebuild ...
This way the web project will be recompiled.
perform a publish of the cloud project, for example
MsBuild solution.sln /t:cloudproject.ccproj:publish ...
The web project will be copied correctly to the cspack file.