Can't exclude *.dcproj from dotnet pack - docker-compose

I used Visual Studio 2017 to make a solution with docker-compose support. When I try to pack a nuget package (during a CI process) using dotnet pack MySolution.sln I getting the error MSB4057 saying that it cannot pack the docker-compose.dcproj project. So I tried to use <IsPackable>false</IsPackable> inside my docker-compose.dcproj with no success.
So I have to pack my projects one by one or use different solutions for CI and for debugging process - both solutions looks ugly to me.
Does anyone have an idea how to exclude .dcproj file from trying to been packed by dotnet pack?

In the CI script, remove the docker-compose project from the solution before the pack command with
dotnet sln MySol.sln remove docker-compose.dcproj

I had the same problem and I have solved it by adding a dummy "Pack" target to docker-compose.dcproj, so my project looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
<PropertyGroup Label="Globals">
<ImportDirectoryBuildProps>false</ImportDirectoryBuildProps>
<ImportDirectoryBuildTargets>false</ImportDirectoryBuildTargets>
<ProjectVersion>2.1</ProjectVersion>
<DockerTargetOS>Windows</DockerTargetOS>
<ProjectGuid>0a1c7d45-3174-4d07-a025-4d5fd55042c0</ProjectGuid>
<IsPackable>false</IsPackable>
<IsTestProject>false</IsTestProject>
</PropertyGroup>
<PropertyGroup>
<DockerServiceName>app-name</DockerServiceName>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose.override.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.yml" />
</ItemGroup>
<Target Name="Pack">
</Target>
</Project>

Related

Azure DevOps build pipeline for Service Fabric Guest .Net Core 3.1 API exe fails on creating package

I have a .NET Core 3.1 API that I am attempting to deploy as a Guest Executable in Service Fabric using an Azure DevOps build pipeline. The platform for all projects/configurations is x64.
I have locally tested the API and also locally tested the API running as a guest executable within service fabric. I am able to build/rebuild the API and I am able to package the service fabric application.
In my build pipeline, I have the following steps shown in the picture below.
The Create Service Fabric Package is defined in the picture below
When the build pipeline runs, it always fails with the error:
##[error]AppraisalStatusUpdatesContainer\AppraisalStatusUpdatesContainer.sfproj(0,0): Error MSB4057: The target "Package" does not exist in the project.
I cannot find any documentation on what to do to solve this issue and have spent a couple of days trying. Does anyone know how to get this to work?
Edit 1
The sfproj is provided below
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.props" Condition="Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.props')" />
<PropertyGroup Label="Globals">
<ProjectGuid>ffefa7ed-cf72-4780-9910-816deed2ed4f</ProjectGuid>
<ProjectVersion>2.5</ProjectVersion>
<MinToolsVersion>1.5</MinToolsVersion>
<SupportedMSBuildNuGetPackageVersion>1.6.10</SupportedMSBuildNuGetPackageVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<None Include="ApplicationPackageRoot\ApplicationManifest.xml" />
<None Include="ApplicationParameters\Prod.xml" />
<None Include="ApplicationParameters\QA.xml" />
<None Include="ApplicationParameters\UAT.xml" />
<None Include="ApplicationParameters\Local.1Node.xml" />
<None Include="ApplicationParameters\Local.5Node.xml" />
<None Include="PublishProfiles\QA.xml" />
<None Include="PublishProfiles\UAT.xml" />
<None Include="PublishProfiles\Prod.xml" />
<None Include="PublishProfiles\Local.1Node.xml" />
<None Include="PublishProfiles\Local.5Node.xml" />
<None Include="Scripts\Deploy-FabricApplication.ps1" />
</ItemGroup>
<ItemGroup>
<Content Include="..\AppraisalStatusUpdates\bin\Release\netcoreapp3.1\publish\**\*.*">
<Link>ApplicationPackageRoot\AppraisalStatusUpdatesContainerPkg\Code\%(RecursiveDir)%(Filename)%(Extension)</Link>
</Content>
<Content Include="ApplicationPackageRoot\AppraisalStatusUpdatesContainerPkg\Config\Settings.xml" />
<Content Include="ApplicationPackageRoot\AppraisalStatusUpdatesContainerPkg\ServiceManifest.xml" />
<Content Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
<PropertyGroup>
<ApplicationProjectTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Service Fabric Tools\Microsoft.VisualStudio.Azure.Fabric.ApplicationProject.targets</ApplicationProjectTargetsPath>
</PropertyGroup>
<Import Project="$(ApplicationProjectTargetsPath)" Condition="Exists('$(ApplicationProjectTargetsPath)')" />
<Import Project="..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets" Condition="Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets')" />
<Target Name="ValidateMSBuildFiles" BeforeTargets="PrepareForBuild">
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.props')" Text="Unable to find the '..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.props' file. Please restore the 'Microsoft.VisualStudio.Azure.Fabric.MSBuild' Nuget package." />
<Error Condition="!Exists('..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets')" Text="Unable to find the '..\packages\Microsoft.VisualStudio.Azure.Fabric.MSBuild.1.6.10\build\Microsoft.VisualStudio.Azure.Fabric.Application.targets' file. Please restore the 'Microsoft.VisualStudio.Azure.Fabric.MSBuild' Nuget package." />
</Target>
</Project>
Edit 2
#LeoLiu-MSFT, I have attempted the approach you mentioned. I am not getting the original error, but am now attempting to resolve the subsequent issues that resulted. Also, I am doing dotnet publish and dotnet test tasks before this step. It seems like the publish step is unnecessary except that it is needed for running the tests.
My msbuild step is now as follows
This results in the exception below:
##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(777,5): Error : The OutputPath property is not set for project 'AppraisalStatusUpdatesContainer.sfproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Release' Platform='x64'. You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project.
I have a custom Powershell script in my service fabric repositories for this.
It does a separate nuget restore for .sfproj.
The script restore-sf.ps1:
Push-Location $PSScriptRoot
$ProjectFolder = "..\src\YourProjectFolder"
$PackageFolder = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\Packages"))
Push-Location $ProjectFolder
nuget restore YourServiceFabricProject.sfproj -PackagesDirectory $PackageFolder -MSBuildVersion 15
Pop-Location
Pop-Location
My folder structure:
├───Root
├───packages
├───src
├───YourProjectFolder
├───YourServiceFabricProject.sfproj
├───scripts
├───restore-sf.ps1
Depending on your folder structure, you'll need to change the paths in the script.
In the pipeline one of the first steps is to call the script, to restore the Microsoft.VisualStudio.Azure.Fabric.MSBuild package.
The script assumes nuget is available in the path.
Azure DevOps build pipeline for Service Fabric Guest .Net Core 3.1 API exe fails on creating package
According to the error:
MSB4057: The target "Package" does not exist in the project.
When you are using MSBuild for a solution of projects (.sln) with target Package, but not all projects have the Package task defined. That may be one of the reasons why you get this error.
To resolve this issue, we could add following custom target in the .sfproj file:
<Target Name="ForcePackageTarget" AfterTargets="Build" Condition="'$(ForcePackageTarget)' =='true'">
<CallTarget Targets="Package"/>
</Target>
Then add /p:ForcePackageTarget=true as an argument to the msbuild build task.
Please check this thread and this post for some more details.

Visual Studio Code adding Microsoft.EntitiyFrameworkCore.dll

unfortunately the PC I am working with has no Internet Connection and only Visual Studio Code. So far I have not been able to install the microsoft.entityframeworkcore.3.1.4.nupkg package. So I was thinking about just using the dll but keep everything else in the project like usual.
In my class I want to call:
using Microsoft.EntitiyFrameworkCore;
my csproj file looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
</ItemGroup>
<Reference Include="Microsoft.EntityFrameworkCore">
<HintPath>..\Framework\Microsoft.EntityFrameworkCore.dll</HintPath>
</Reference>
</Project>
I also copied the dll to the debug and release folder, as well as the Framework folder. Can someone give me a hint what I am missing? I assume locally add the nupkg package just by a command line without internet and without the full version of Visual Studio is impossible.
Thanks
Stephan
I think I forgot the itemgroup:
<ItemGroup>
<Reference Include="Microsoft.EntityFrameworkCore">
<HintPath>\Framework\Microsoft.EntityFrameworkCore.dll</HintPath>
</Reference>
</ItemGroup>

Including referenced projects in NuGet package

I have the following project in my solution which I am trying to use to create a NuGet package:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>ExpressionTreeTestObjects</PackageId>
<Authors>Zev Spitz</Authors>
<Company />
<Product>ExpressionTreeTestObjects</Product>
<Description>A set of expression trees, and instances of other types from System.Linq.Expressions, for testing code against a variety of expression trees. The objects are generated by the C# compiler, by the VB.NET compiler, or using the factory methods at System.Linq.Expressions.Expression.</Description>
<Copyright>Copyright (c) 2019 Zev Spitz</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/zspitz/ExpressionTreeToString</PackageProjectUrl>
<RepositoryUrl>https://github.com/zspitz/ExpressionTreeToString</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>expression-tree code-generation visual-basic.net vb.net csharp test-data tostring</PackageTags>
<IncludeBuildOutput>true</IncludeBuildOutput>
<IncludeReferencedProjects>true</IncludeReferencedProjects>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ExpressionTreeTestObjects.VB\TestObjects.VB.vbproj" />
<ProjectReference Include="..\ExpressionTreeTestObjects\TestObjects.csproj" />
</ItemGroup>
</Project>
Build and pack both seem to work. However, the .nupkg file doesn't seem to include the referenced DLLs.
How can I troubleshoot this? How can I resolve it?
I think the solution can be found here:
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
<ItemGroup>
<BuildOutputInPackage Include="#(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
</ItemGroup>
</Target>

NuGet Package Restore: Visual Studio Online & POSTSHARP

I installed POSTSHARP as a nuget package and I want Visual Studio Online to automatically restore it.
POSTSHARP must be restored before build though.
I am trying to follow this with no success: link
How can I run scripts / commands in Visual Studio Online BEFORE build?
There are instructions on nuget.org on how to set up a package restore with TFS, including Visual Studio Online: http://docs.nuget.org/docs/reference/package-restore-with-team-build
It mentions that the default Build Process Templates for VSO already implements NuGet Package Restore workflow. So, supposedly, you need to do additional setup only when you customize the templates.
The proposed approach is to create a simple MSBuild project file that will be used to build the solution. You can include all the required targets there (e.g. Build, Rebuild, Clean) that will just invoke MSBuild on your solution file with specifying the corresponding target.
Additionally create a target for package restore - it will invoke NuGet.exe restore MySolution.sln command. The common build targets will depend on this one.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutDir>$(MSBuildThisFileDirectory)bin</OutDir>
<Configuration>Release</Configuration>
<ProjectProperties>
OutDir=$(OutDir);
Configuration=$(Configuration);
</ProjectProperties>
</PropertyGroup>
<ItemGroup>
<Solution Include="$(MSBuildThisFileDirectory)src\*.sln" />
</ItemGroup>
<Target Name="RestorePackages">
<Exec Command=""$(MSBuildThisFileDirectory)tools\NuGet\NuGet.exe" restore "%(Solution.Identity)"" />
</Target>
<Target Name="Build" DependsOnTargets="RestorePackages">
<MSBuild Targets="Build"
Projects="#(Solution)"
Properties="$(ProjectProperties)" />
</Target>
<!-- other targets... -->
</Project>

Is there a way to create more than one deployment with msbuild on a single build?

I am using msbuild command line multiple times to create a deployment zip file for my dev / test / production websites. I have already configured the parameters and configuration xml for each one. I want to know if i can condense my 3 calls to msbuild down to one, and have it build all three at once?
right now i have to run
msbuild.exe myproject.sln /T:Build /p:DeployOnBuild=True /p:PublishProfile="Dev Server"
msbuild.exe myproject.sln /T:Build /p:DeployOnBuild=True /p:PublishProfile="Prod Server"
etc
The continuous deployment solution i'm using (bamboo) is struggling with this multiple call to msbuild for some reason (i have an open ticket and they are perplexed as well). I'm trying to simplify things.
I have a template for building out all skus of the same solution in parallel.
This is the same concept as Stijn's approach that uses an ItemGroup as a project definition rather than a series of options for a particular property + the msbuild task will build both at the same time, saving you time and bubbling up any configuration issues when building in parallel.
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<SolutionToBuild Include="$(MSBuildThisFileDirectory)\MyProject.sln">
<Properties>DeployOnBuild=True;PublishProfile="Dev Server"</Properties>
</SolutionToBuild>
<SolutionToBuild Include="$(MSBuildThisFileDirectory)\MyProject.sln">
<Properties>DeployOnBuild=True;PublishProfile="Prod Server"</Properties>
</SolutionToBuild>
</ItemGroup>
<Target Name="Build">
<MsBuild BuildInParallel="true" ContinueOnError="true" Projects="#(SolutionToBuild)" />
</Target>
<Target Name="Clean">
<MsBuild BuildInParallel="true" ContinueOnError="true" Projects="#(SolutionToBuild)" Targets="Clean" />
</Target>
</Project>
You can only invoke multiple different targets on the commandline, but you can't supply multiple different values for properties. At least not in a way that I'm aware off. The workaround however is simple, easier to extend than a commandline, and the typical msbuild way of doing things: create a master build file like below and call it from Bamboo instead of the solution.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets=Build>
<Target Name="Build">
<ItemGroup>
<PublishProfiles Include="Dev Server"/>
<PublishProfiles Include="Prod Server"/>
</ItemGroup>
<MsBuild Projects="myproject.sln" Targets="Build"
Properties="DeployOnBuild=True;PublishProfile=%(PublishProfile.Identity)"/>
</Target>
</Project>
(this will invoke MsBuild myproject.sln once for each item in the PublishProfiles list with the properties as shown)