I'm trying to use a publish profile with the msbuild command in a PowerShell window on a machine that does not have the full Visual Studio IDE installed. I have tried the following:
msbuild.exe .\Web.Admin.csproj /p:'DeployOnBuild=true;PublishProfile=Default;'
MSBuild.exe .\Web.Admin.csproj /p:PublishProfile=Default /p:VisualStudioVersion=14.0
msbuild.exe .\Web.Admin.csproj /p:PublishProfileRootFolder=C:\Users\username\Projects\Web\Web.Admin\Properties\PublishProfiles /p:PublishProfile=Default
In both cases, the publish profile seems to be ignored. This is the publish profile, generated by Visual Studio (in Properties\PublishProfiles\Default.pubxml):
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>True</ExcludeApp_Data>
<publishUrl>C:\Sites\Test</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<PrecompileBeforePublish>True</PrecompileBeforePublish>
<EnableUpdateable>True</EnableUpdateable>
<DebugSymbols>False</DebugSymbols>
<WDPMergeOption>DonotMerge</WDPMergeOption>
</PropertyGroup>
</Project>
The files are not published to the C:\Sites\Test directory specified, as they would be if I ran this with the Publish command in Visual Studio 2017. Instead they go to the project bin directory.
MSBuild Version: 14.0.23107.0
Related
I'm successfully publishing a .NET Core App via Visual Studio but am unable to do the same via command-line (or using the Developer Command Prompt for VS 2019).
I'm using the Publish profile generated by VS2019 and doing:
dotnet publish -p:PublishProfile=Properties\PublishProfiles\MyProfile.pubxml
where MyProfile is:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PublishDir>..\Build\Release\publish\</PublishDir>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
</Project>
And the error that I always get is:
MyCustom.dll. Could not load type
'Microsoft.Build.Utilities.AppDomainIsolatedTask' from assembly
'Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'. Confirm that the
declaration is correct, that the assembly and all its dependencies are
available, and that the task contains a public class that implements
Microsoft.Build.Framework.ITask.
What am I missing?
I found a workaround, rather than a fix.
If we use msbuildto publish, I'm able to have the same result as dotnet publish and it runs successfully in the command-line:
msbuild /restore /t:Publish /p:RuntimeIdentifier=win-x64 /p:configuration=Release
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 am creating a ASP.net core 2.0 WEB API project that is required to be deploy as a Windows service on a system using a MSI setup. Is there any way I can do it ?
Things that I have already tried:
I created an MSI using Setup Project but it doesn't load any dependencies.
I tried to create an msi using WIX but it shows error The WiX Toolset v3.11 (or newer) build tools must be installed to build this project I have tried solution which are already answered on this and this.
Short on time, just some links to see if it gets you going:
Various Deployment Tools (quick rundown of deployment tools for MSI creation)
WiX Quick Start Suggestions (oddly enough this answer seems to help people)
A very quick overview of MSI (also see the top links to installsite.org's rundown of setup tools)
Essentially:
You need to download and install the WiX toolkit to run WiX.
If you want to work with WiX source files in Visual Studio, you should also get the Visual Studio Extension (in addition to the main WiX download).
Download both from here: http://wixtoolset.org/releases/
I like to add the bin folder in the main WiX installation directory to the Path environment variable to be able to call WiX build tools - candle.exe, light.exe, etc... - from anywhere.
You can compile WiX source files outside Visual Studio as well. In its simplest form:
set SetupName=MySetup
candle.exe %SetupName%.wxs >> %SetupName%.log
light.exe -out %SetupName%.msi %SetupName%.wixobj >> %SetupName%.log
Or, without the line-noise:
candle.exe Setup.wxs
light.exe -out Setup.msi Setup.wixobj
Similar Questions:
Visual Studio 2017 C# installer project is not installing my app
I solved this by creating an msi using Wix. I watched this Video and followed its instruction.
For creating windows service I used NSSM, I copied nssm.exe as a part of installer.
used the following command:
nssm install service-name
For creating service automatically I used the CustomAction of WiX.
To create an MSI for .Net core 2… first publish your project like
dotnet publish --configuration Release --runtime win7-x64 --self-contained false --output c:\outputfolder
You can make it part of your .wixproj by adding
<Target Name="BeforeBuild">
<PropertyGroup>
<BasePath>$(SolutionDir)\publish\bin\$(Configuration)\FilesToPackage</BasePath>
</PropertyGroup>
<!-- Clean previous build folder -->
<Exec Command="rd /s /q $(BasePath)" />
<!-- Publish dotnet core app -->
<Exec Command="dotnet publish $(MSBuildThisFileDirectory)\..\..\src\yourproject.csproj -r win-x64 --self-contained false --output $(BasePath)" />
<!-- Get assembly version -->
<GetAssemblyIdentity AssemblyFiles="$(BasePath)\yourproject.dll">
<Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
</GetAssemblyIdentity>
<!-- Define some variables we need -->
<PropertyGroup>
<DefineConstants>ProductVersion=%(AssemblyVersion.Version);BasePath=$(BasePath)</DefineConstants>
</PropertyGroup>
<HeatDirectory
OutputFile="YourServiceComponent.wxs"
DirectoryRefId="INSTALLFOLDER"
ComponentGroupName="yourproject_component"
SuppressCom="true" Directory="$(BasePath)"
SuppressFragments="true"
SuppressRegistry="true"
SuppressRootDirectory="true"
AutoGenerateGuids="false"
GenerateGuidsNow="true"
ToolPath="$(WixToolPath)"
PreprocessorVariable="var.BasePath"
Transforms="RemoveFiles.xslt"
/>
</Target>
Heat will create the wxs file with all the files from the output but you need to remove yourservice.exe so add that information to RemoveFiles.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<xsl:output method="xml" indent="yes" />
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:key name="pdb-search" match="wix:Component[contains(wix:File/#Source, '.pdb')]" use="#Id" />
<xsl:template match="wix:Component[key('pdb-search', #Id)]" />
<xsl:template match="wix:ComponentRef[key('pdb-search', #Id)]" />
<xsl:key name="service-search" match="wix:Component[contains(wix:File/#Source, 'Your.Service.exe')]" use="#Id"/>
<xsl:template match="wix:Component[key('service-search', #Id)]"/>
<xsl:template match="wix:ComponentRef[key('service-search', #Id)]"/>
</xsl:stylesheet>
Finally you want Wix to register your service with Windows Service Control Manager (SCM) so add the following to your Product.wxs
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<ComponentGroupRef Id="yourproject_component" />
<Component Id="ServiceAssemblyComponent" Guid="{GUID}">
<File Id="ServiceAssembly" Source="$(var.BasePath)\Your.Service.exe" KeyPath="yes" />
<ServiceInstall Id="ServiceInstallation" DisplayName="$(var.ProductName)" Name="$(var.ProductName)" ErrorControl="normal" Start="auto" Type="ownProcess" Vital="yes" />
<ServiceControl Id="ServiceControl" Name="$(var.ProductName)" Stop="both" Remove="uninstall" />
</Component>
</ComponentGroup>
</Fragment>
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 am learning how to develop PowerShell module in c# but there is no Visual Studio integration to launch PowerShell with the module imported.
I would like to configure MSBuild to launch PowerShell and run Import-Module $(TargetFileName).
I configured my project as a library project and set the debug options to launch PowerShell and set the command line argument to -NoExit -Command "Import-Module .\PowerShellModule.dll". However I am not satisfied with this solution.
My goal is to launch PowerShell with the module i'm working loaded and the debugger attached when I press F5 in Visual Studio. Ideally I would like to use the MSBuild Macro to create a reusable template and avoid using the csproj.user file.
Here is the relevent csproj.user file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>-NoExit -Command "Import-Module .\PowerShellModule.dll "</StartArguments>
<StartAction>Program</StartAction>
<StartProgram>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</StartProgram>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<StartAction>Program</StartAction>
<StartProgram>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</StartProgram>
<StartArguments>
</StartArguments>
</PropertyGroup>
</Project>
I was able to achieve what I wanted by adding the following lines under PropertyGroup in my csproj.
<StartAction>Program</StartAction>
<StartProgram>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</StartProgram>
<StartArguments>-NoExit -Command "Import-Module .\$(AssemblyName).dll"</StartArguments>