I am using the new MSBuild 15 distributed with VS2017 RC to compile and pack a multi targeting project.
Restoring: msbuild /t:restore mysolution.sln works correctly.
Building: msbuild /p:Configuration=Release mylibrary.csproj works correctly and generates:
+ bin/Release
+ netstandard1.4
- mylibrary.dll
+ net452
- mylibrary.dll
But when I am packing: msbuild /t:pack /p:Configuration=Release /p:IncludeSymbols=true mylibrary.csproj the structure does not match well with the previous build, looking like:
+ bin/Release
+ netstandard1.4
- mylibrary.pdb
+ net452
- mylibrary.pdb
- mylibrary.dll
Warnings from the /t:pack command show me this was gonna happen, but not sure how to solve it:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(73,5): warning : Issue found with package 'MyLibrary'. [D:\XXX\YYY\src\MyLibrary\MyLibrary.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(73,5): warning : Issue: Assembly not inside a framework folder. D:\XXX\YYY\src\MyLibrary\MyLibrary.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(73,5): warning : Description: The assembly 'lib\MyLibrary.dll' is placed directly under 'lib' folder. It is recommended that assemblies be placed inside a framework-specific folder.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(73,5): warning : Solution: Move it into a framework-specific folder. If this assembly is targeted for multiple frameworks, ignore this warning.
Notes:
I am not using a *.nuspec file. Just the new way *.csproj files work (https://docs.nuget.org/ndocs/schema/msbuild-targets#pack-target)
This is how some of the relevant content of the file look like:
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>library</OutputType>
<TargetFrameworks>netstandard1.4;net452</TargetFrameworks>
<AssemblyName>MyLibrary</AssemblyName>
<Authors>XXX</Authors>
<Description>YYY</Description>
<PackageId>MyLibrary</PackageId>
<PackageVersion>1.2.3</PackageVersion>
</PropertyGroup>
</Project>
Thanks for your comments. I found my way on based on them.
This is what I did: I downloaded the dotnet cli tool again and test it from scratch. I realized that the version of the cli tool were the same so I started comparing the files inside.
Wrong dotnet cli version
The version that was not working contained the following files:
+ dotnet
+ sdk
+ 1.0.0-preview2-1-003177
+ 1.0.0-preview2-003131
+ 1.0.0-preview2-003133
+ 1.0.0-preview4-004233
Using dotnet build /t:pack /p:Configuration=Release /p:IncludeSymbols=true mylibrary.csproj showed the following error:
Couldn't find 'project.json' in '/t:pack'
Good dotnet cli version
The second version I downloaded contained only these:
+ dotnet
+ sdk
+ 1.0.0-preview4-004233
And executing the command before, it works correctly:
Microsoft (R) Build Engine version 15.1.458.808
Copyright (C) Microsoft Corporation. All rights reserved.
...
Related
Previous title:
The "GenerateFileFromTemplate" task was not found
.NET project template - GeneratedContent
.csproj.in file transformations
The troubled package is Microsoft.DotNet.Build.Tasks.Templating.
I've created a git-repository containing multiple .NET project templates. When opened in Visual Studio, VS had a horrible performance when adding more files to the template project. This turned out to be caused by my template's project files having .csproj extension. Therefor I've changed the extensions of all my template csproj files to csproj.in.
Because of this, I need to add a msbuild task that transforms this .csproj.in to .csproj. There are several examples out on the internet:
ASP.NET Core project templates
spa-templates (Seems to use the Arcade SDK)
dotnet-template-samples (very basic)
microsoft/SEAL
In the above samples, there is no nuget.config in the project.
Your root csproj file contains a <GeneratedContentProperties> and <GeneratedContent> section:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<GeneratedContentProperties>
DefaultNetCoreTargetFramework=$(DefaultNetCoreTargetFramework);
</GeneratedContentProperties>
</PropertyGroup>
<ItemGroup>
<GeneratedContent Include="Angular-CSharp.csproj.in" OutputPath="content/Angular-CSharp/Company.WebApplication1.csproj" />
<GeneratedContent Include="React-CSharp.csproj.in" OutputPath="content/React-CSharp/Company.WebApplication1.csproj" />
</ItemGroup>
</Project>
The .csproj.in files reference the GeneratedContentProperties:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>${DefaultNetCoreTargetFramework}</TargetFramework>
...
</PropertyGroup>
...
</Project>
I've tried applying the same files to my project in this commit, but I'm still getting the following error when building the project:
dotnet build --configuration Release
MSBuild version 17.3.0+92e077650 for .NET
Determining projects to restore...
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets(152,5): warning NETSDK1023: A PackageReference for 'Microsoft.DotNet.Build.Tasks.Templating' was included in your project. This package is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs [C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.
IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj]
...
All projects are up-to-date for restore.
...
C:\repos\MintPlayer.AspNetCore.Templates\eng\GenerateContent.targets(27,3): error MSB4036: The "GenerateFileFromTemplate" task was not found. Check the following:
1.) The name of the task in the project file is the same as the name of the task class.
2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface.
3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files\dotnet\sdk\6.0.400" directory
[C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj]
Build FAILED.
It seems that dotnet cannot find the GenerateFileFromTemplate Task...
I also see that the spa-templates project is using the Arcade SDK, but I don't think I'd actually need that...
How can I fix this? What am I still missing here?
EDIT
When I open both projects in Visual Studio, this is what I see:
Nuget packages for my template project:
C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates> dotnet restore
Determining projects to restore...C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj : warning NU1604: Project dependency Microsoft.DotNet.Build.Tasks.Templating does not contain an inclusive lower bound.
Include a lower bound in the dependency version to ensure consistent restore results.
C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj : error NU1101: Unable to find package Microsoft.DotNet.Build.Tasks.Templating. No packages exist with this id in source(s): C:\Program Files\dotnet\library-packs, Local, Microsoft Visual Studio Offline Packages, nuget.org
Failed to restore C:\repos\MintPlayer.AspNetCore.Templates\MintPlayer.AspNetCore.IdentityServer.Templates\MintPlayer.AspNetCore.IdentityServer.Templates.csproj (in 516 ms).
Nuget packages for spa-templates:
C:\repos\spa-templates\src> dotnet restore
Determining projects to restore...
C:\repos\spa-templates\src\Microsoft.DotNet.Web.Spa.ProjectTemplates.csproj : warning NU1603: Microsoft.DotNet.Web.Spa.ProjectTemplates.7.0 depends on Microsoft.DotNet.Build.Tasks.Templating (>= 6.0.0-beta.21373.11) but Microsoft.DotNet.Build.Tasks.Templating 6.0.0-beta.21373.11 was not found. An approximate best match of Microsoft.DotNet.Build.Tasks.Templating 6.0.0-beta.22212.5 was resolved.
All projects are up-to-date for restore.
So it seems that dotnet restore is unable to restore this package. However, the nuget sources are the same for both projects:
IdentityServer.Templates>dotnet nuget list source
Registered Sources:
1. nuget.org [Enabled]
https://api.nuget.org/v3/index.json
2. Local [Enabled]
C:\packages
3. Microsoft Visual Studio Offline Packages [Enabled]
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
C:\repos\spa-templates>dotnet nuget list source
Registered Sources:
1. nuget.org [Enabled]
https://api.nuget.org/v3/index.json
2. Local [Enabled]
C:\packages
3. Microsoft Visual Studio Offline Packages [Enabled]
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
EDIT 2
Hmm, it seems that GenerateFileFromTemplate is part of the Arcade SDK... (Howto)
How to install Microsoft.DotNet.Arcade.Sdk into the dotnet sdk folder?
It seems that the package is only available through the following NuGet feed:
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json
So I added a nuget.config in the root of the project/repository:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
</packageSources>
</configuration>
And since there's only preview versions of the package, you need for example the following version (eng/Versions.props):
<Project>
...
<PropertyGroup Label="Package versions">
<MicrosoftDotNetBuildTasksTemplatingVersion>6.0.0-beta.21373.11</MicrosoftDotNetBuildTasksTemplatingVersion>
...
</PropertyGroup>
</Project>
I have this one liner that can publish my project:
& "$($linkToMSBuildEXE)" "$($solutionName)" /t:projectName /p:Configuration="Release"
I need to publish this project and set the assemblyVersion and fileVersion of the output executable. I have tried adding the version:
& "$($linkToMSBuildEXE)" "$($solutionName)" /t:projectName /p:Configuration="Release"/p:Version=1.1.1.1
This doesn't seem to work. Do I need to add an entry to the csproj file? How can I set the versions via the command line.
Install MSBuild.AssemblyVersion package from NuGet.
Use the following or similar command line:
msbuild project.csproj /t:Rebuild /p:AssemblyVersionNumber=1.2.3.4
We have over 20 solutions in our main product portfolio (over 880 projects), and we have a complex set of build scripts that work well, but we are trying to automate the restore of nuget packages from within the msbuild pipeline. Currently this is done with a manual call out to nuget to restore the packages.
According to https://learn.microsoft.com/en-us/nuget/schema/msbuild-targets I should be able to run this command and have the restore run:
# works
& $script:msBuildPath $solutionName /t:build /v:q /clp:ErrorsOnly /nologo /p:...
# doesn't works
& $script:msBuildPath $solutionName /t:restore,build /v:q /clp:ErrorsOnly /nologo /p:...
However, when I add the restore, to the above it throws an error
MSB4057: The target "restore" does not exist in the project
Where do I start researching to understand why it can't find this target? We are predominantly on VS 2015 and .NET 4.6.2, so anything specific to VS2017 is not an option for me at this time.
If I omit the /v:q and /clp:ErrorsOnly flags I do get this (slightly sanitized solution/project names and paths)
PS Z:\git\company> build c
building Common\Common.sln
Build started 11/15/2017 11:08:54 AM.
1>Project "Z:\git\company\Common\Common.sln" on node 1 (restore;build target(s)).
1>ValidateSolutionConfiguration:
Building solution configuration "DEBUG|Any CPU".
1>Z:\git\company\Common\Common.sln.metaproj : error MSB4057: The target "restore" does not exist in the project. [Z:\git\company\Common\Common.sln]
1>Done Building Project "Z:\git\company\Common\Common.sln" (restore;build target(s)) -- FAILED.
Build FAILED.
"Z:\git\company\Common\Common.sln" (restore;build target) (1) ->
Z:\git\company\Common\Common.sln.metaproj : error MSB4057: The target "restore" does not exist in the project. [Z:\git\company\Common\Common.sln]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.03
runBuildPackage : ... failed
At Z:\git\company\psincludes\buildFunctions.ps1:11 char:5
+ runBuildPackage "Common\Common.sln"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,runBuildPackage
msbuild failed
At Z:\git\company\psincludes\buildInternals.ps1:63 char:21
+ throw "msbuild failed";
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (msbuild failed:String) [], RuntimeException
+ FullyQualifiedErrorId : msbuild failed
I realize some of this around is our internal tooling, I just didn't feel the need to obscure that part.
According to "the internet" this should just be "free" as part of the build process, and I'm not sure what we are missing in the csproj files here.
The msbuild-integrated NuGet functionality is available in NuGet 4.0+ in conjunction with MSBuild 15, which means only in VS 2017. There is no support for the restore target for VS 2015.
The integrated restore in VS 2017 / NuGet 4 only works for projects using the new PackageReference style of referencing NuGet packages. It does not work for projects using packages.config. This new way of referencing packages is the default option for ASP.NET Core (both on .NET Framework / .NET Core), .NET Core and .NET Standard projects. It is opt-in for all other project types by selecting the style before the first install in the NuGet properties (Tools->Options->NuGet).
Note that calling /t:Restore,Build is not a good way to call this target, since restore may generate or change files that msbuild then doesn't reload. MSBuild 15.5 (upcoming update to VS 2017) introduces a /restore option instead that will call the restore target, then clear all caches which could not be cleared before and execute the normal build as requested. Before 15.5, it is best to make two distinct calls to msbuild.
I'm attempting to compile my new C# 7 code on a Linux build server using Mono 5. Unfortunately, the project fails when I use the new ValueTuple syntax:
MyClass.cs(100,38): error CS1003: Syntax error, '(' expected [/path/to/My.csproj]
I have the following package reference in my project file:
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
and I'm using the following commands in my quick build script:
# msbuild My.sln /t:restore
# msbuild My.sln /p:Configuration=Release /p:Platform="Any CPU"
and the MSBuild log indicates a language version of 7 and shows a reference to System.ValueTuple.dll:
CoreCompile:
/usr/lib/mono/4.5/csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1705,1701,1702 /langversion:7 /nostdlib+ /errorreport:prompt /warn:4 /doc:bin/Release/net461/My.xml /define:TRACE;RELEASE;NET461 /highentropyva+ ... /reference:/root/.nuget/packages/system.valuetuple/4.3.0/lib/netstandard1.0/System.ValueTuple.dll ... /debug- /debug:portable /filealign:512 /nologo /optimize+ /out:obj/Release/net461/My.dll /subsystemversion:6.00 /target:library /warnaserror- /utf8output /deterministic+ My.cs "/tmp/.NETFramework,Version=v4.6.1.AssemblyAttributes.cs" obj/Release/net461/My.AssemblyInfo.cs
Has anyone successfully compiled C# using the new ValueTuple syntax on Linux using Mono 5? Did it just work, or did you need to adjust the environment to make it work?
My build server is running Ubuntu 16.04 and has mono-devel 5.0.1.1-0xamarin5+ubuntu1604b1 installed.
I uninstalled the stable mono-devel 5.0.1.1-0xamarin5+ubuntu1604b1 and replaced it with the beta mono-devel 5.2.0.196-0xamarin7+ubuntu1604b1. The project now compiles without error.
I will assume that a bug in mono has been fixed that resolves this issue.
I have an .WPF application.Using XBAP project the project as web application. The solution file having 15 projects. Among 15 projects, one is root project names 'cp'. This has other project dll. i am able to build the code. My goal is that to Publish in one Location (Ex: c:\publish)in the file format of '.deploy' of all the project(Ex: sampleproject.dll.deploy). How command should i use.? I have tried following command one by one. Nothing give proper .deploy package.
R&D
msbuild cp.sln /p:DeployOnBuild=true /p:PublishProfile=Test
msbuild cp.sln /p:DeployOnBuild=true;DeployTarget=PipelinePreDeployCopyAllFilesToOneFolder;PackageTempRootDir="C:\Publish";AutoParameterizationWebConfigConnectionStrings=false
msbuild cp.sln /p:DeployOnBuild=true;DeployTarget=Package
msbuild cp.sln /p:DeployOnBuild=true /p:PublishProfile=FileSystemDebug
msbuild cp.sln /p:DeployOnBuild=true /p:PublishProfile=myprofile
msbuild cp.csproj /p:DeployOnBuild=true /p:PublishProfile=myprofile.
msbuild cp.csproj "/p:Platform=AnyCPU;Configuration=Release;PublishDestination=C:\Publish" /t:PublishToFileSystem
If you set your publish profile and publish directory is "c:\publish" you should use the following windows commands. I suppose that You are using MSbuild 14.0.
For Windows Machine
C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /p:DeployOnBuild=true /p:PublishProfile="C:\PublishProfiles\testprofile.pubxml" "C:\Myapp\Myproject.sln"
For Azure
C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /p:DeployOnBuild=true /p:AllowUntrustedCertificate=true /p:PublishProfile="C:\PublishProfiles\testprofile.pubxml" /p:Password=xxxxx "C:\Myapp\Myproject.sln"