When I run MSDeploy from a build script, I get this NullReferenceException. The funny thing is, the project deploys. This has been driving me crazy. Note: This is a web site project, not a web application project.
I'm using this in my build targets file:
<ItemGroup>
<DeploySource Include="DirPath">
<Path>C:\TFS\MySiteBranch\PrecompiledWeb\Source</Path>
<ComputerName>myComputer</ComputerName>
<UserName>anAdminAccount</UserName>
<Password>itsPassword</Password>
</DeploySource>
</ItemGroup>
<ItemGroup>
<TestDeployDest Include="DirPath">
<Path>C:\TFS_Build\POC\Test</Path>
<ComputerName>myComputer</ComputerName>
<UserName>anAdminAccount</UserName>
<Password>itsPassword</Password>
</TestDeployDest>
</ItemGroup>
<Target name="Deploy">
<PropertyGroup>
<WhatIf Condition="'$(WhatIf)'==''">false</WhatIf>
<MSDeployPath Condition="'$(MSDeployPath)'==''">C:\Program Files\IIS\Microsoft Web Deploy V2</MSDeployPath>
</PropertyGroup>
<MSDeploy Condition="'#(TestDeployDest)'!=''"
Whatif="$(WhatIf)"
Verb="sync"
Source="#(DeploySource)"
Destination="#(TestDeployDest)"
ExePath="$(MSDeployPath)"
/>
</target>
Here's the error:
"C:\TFS\MySiteBranch\Source\source.csproj" (Deploy target) (1) ->
(Deploy target) ->
C:\TFS\MySiteBranch\Source\Deploy.Targets(54,3): error MSB4018: The "MSDeploy" task failed unexpectedly.\r [C:\TFS\MySiteBranch\Source\source.csproj]
C:\TFS\MySiteBranch\Source\Deploy.Targets(54,3): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object.\r [C:\TFS\MySiteBranch\Source\source.csproj]
C:\TFS\MySiteBranch\Source\Deploy.Targets(54,3): error MSB4018: at Microsoft.Web.Publishing.Tasks.Common.Utility.MsDeployEndOfExecuteMessage(Boolean bSuccess, String destType, String destRoot, TaskLoggingHelper Log)\r [C:\TFS\MySiteBranch\Source\source.csproj]
C:\TFS\MySiteBranch\Source\Deploy.Targets(54,3): error MSB4018: at Microsoft.Web.Publishing.Tasks.MSDeploy.Execute()\r [C:\TFS\MySiteBranch\Source\source.csproj]
C:\TFS\MySiteBranch\Source\Deploy.Targets(54,3): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()\r [C:\TFS\MySiteBranch\Source\source.csproj]
C:\TFS\MySiteBranch\Source\Deploy.Targets(54,3): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutio
Any ideas for something I can try?
Try using ContinueOnError="true" on the MSDeploy Elements as the following code:
<ItemGroup>
<DeploySource Include="DirPath">
<Path>C:\TFS\MySiteBranch\PrecompiledWeb\Source</Path>
<ComputerName>myComputer</ComputerName>
<UserName>anAdminAccount</UserName>
<Password>itsPassword</Password>
</DeploySource>
</ItemGroup>
<ItemGroup>
<TestDeployDest Include="DirPath">
<Path>C:\TFS_Build\POC\Test</Path>
<ComputerName>myComputer</ComputerName>
<UserName>anAdminAccount</UserName>
<Password>itsPassword</Password>
</TestDeployDest>
</ItemGroup>
<Target name="Deploy">
<PropertyGroup>
<WhatIf Condition="'$(WhatIf)'==''">false</WhatIf>
<MSDeployPath Condition="'$(MSDeployPath)'==''">C:\Program Files\IIS\Microsoft Web Deploy V2</MSDeployPath>
</PropertyGroup>
<MSDeploy ContinueOnError="true" Condition="'#(TestDeployDest)'!=''"
Whatif="$(WhatIf)"
Verb="sync"
Source="#(DeploySource)"
Destination="#(TestDeployDest)"
ExePath="$(MSDeployPath)"
/>
</target>
I had the same issue; and was just able to address it using the fix described here:
http://forums.iis.net/p/1187159/2016131.aspx#2016131
For me, using the VSMSDeploy task is not an option, as we run x64 servers and web apps. Visual Studio only runs x86 versions of msbuild and msdeploy, and so VSMSDeploy only works for x86 servers and sites. I'm using the appHostConfig provider to store IIS config, and appHostConfig can't sync an x64 site to an x86 instance of msdeploy.
I just ran into the same thing. I wasn't able to figure out what the problem was, but I was able to work around it by using VSMSDeploy instead of MSDeploy. Both tasks are in the same DLL and there are examples of using it in Microsoft.Web.Publishing.targets.
I was able to get the deploy working with a Web Deploy Project.
Related
I emit a console app with Mono.Cecil and I want to integrate MSBuild into the build process. But then when I run dotnet build on my custom project file, MSBuild throws an error saying Expected file "obj\Debug\net5.0\refint\test.dll" does not exist. It's trying to find the generated assembly inside the refint folder. When the assembly gets generated inside obj\Debug\net5.0\test.dll as it should. Is there a way I can change the path where MSBuild looks for the output assembly? Everything on the side of the IL generator works, I even get a runnable exe inside the build folder. Here's my project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<OutputType>Exe</OutputType>
<DefaultLanguageSourceExtension>.ao</DefaultLanguageSourceExtension>
<OutputPath>C:\Users\filip\source\alto\samples\test\obj\Debug\net5.0\</OutputPath>
</PropertyGroup>
<Target Name="CreateManifestResourceNames" />
<Target Name="CoreCompile" DependsOnTargets="$(CoreCompileDependsOn)">
<Exec Command="dotnet run --project "$(MSBuildThisFileDirectory)\..\..\src\aoc\aoc.csproj" -- #(Compile->'$(MSBuildThisFileDirectory)', ' ') /o "#(IntermediateAssembly)" #(ReferencePath->' /r "%(Identity)"', ' ')"
WorkingDirectory="$(MSBuildProjectDirectory)" />
</Target>
</Project>
Thank you in advance.
I didn't read the whole error message.
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4527,5): error : Expected file "obj\Debug\net5.0\refint\test.dll" does not exist.
It actually points me to a file where the error was thrown. This is where:
<!-- Copy the reference assembly build product (.dll or .exe). -->
<CopyRefAssembly
SourcePath="#(IntermediateRefAssembly)"
DestinationPath="$(TargetRefPath)"
Condition="'$(ProduceReferenceAssembly)' == 'true' and '$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)' != 'true'"
>
<Output TaskParameter="DestinationPath" ItemName="ReferenceAssembly"/>
<Output TaskParameter="DestinationPath" ItemName="FileWrites"/>
</CopyRefAssembly>
It's trying to make a reference assembly when I don't need one. So I just set the ProduceReferenceAssembly property to false, since I don't need one.
I have a .NET Core 3 Blazor (server side) application which I recently upgraded to .NET Core 3.0.1 preview 6 version from the preview 5 version. When I build and run it locally, it works fine; but when trying to publish it to a file system folder (in Framework-Dependent mode), it throws this error:
C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(192,5): Error MSB4018: The "TransformAppSettings" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
File name: 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
at Microsoft.NET.Sdk.Publish.Tasks.AppSettingsTransform.UpdateDestinationConnectionStringEntries(String destinationAppSettingsFilePath, ITaskItem[] destinationConnectionStrings)
at Microsoft.NET.Sdk.Publish.Tasks.TransformAppSettings.TransformAppSettingsInternal()
at Microsoft.NET.Sdk.Publish.Tasks.TransformAppSettings.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()
It's perhaps worth mentioning that this error didn't occur in the preview 5 version. Also, I use Visual Studio Enterprise 2019 (Windows).
Things I've tried so far: (with no luck)
Clean/Rebuild solution
Reinstall .NET Core 3 preview 6 SDK
Add Newtonsoft.Json package via Nuget
Search for related issues raised by the community on github
.csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>7.3</LangVersion>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.1.0" />
<PackageReference Include="MatBlazor" Version="1.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="SqlTableDependency" Version="8.5.3" />
<PackageReference Include="System.DirectoryServices" Version="4.5.0" />
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="4.5.0" />
<PackageReference Include="Telerik.UI.for.Blazor" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\images\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\{path to project file}" />
</ItemGroup>
</Project>
In my case, I edit the publish configuration and turned off the Database -> Use this connection at runtime. Then I could publish without this error, however, I had to manually edit the web.config and make the following changes.
modules="AspNetCorModuleV2" had to become modules="AspNetCodeModule"
hostingModel="InProcess" had to become hostingModel="OutOfProcess"
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" /> had to become value="Production"
These changes were already in my own directories web.config, but they didn't seem to get propagated in the publish anymore.
I had this same error and was able to fix it by editing the .pubxml.user file.
When the error occurred, my publish settings didn't have the "Use this connection at runtime" selected, nor were any database migrations checked. But when I looked in the pubxml.user file and it turns out there was a reference to a non-existent database that wasn't showing up in the Publish Settings UI. I removed that and it solved the problem.
All I did was uncheck the "Use this connection string at runtime" database option, since my azure server will that set that anyway it shouldn't be an issue.
I have the same issue
Same Question on Stack Overflow
Though i have managed to publish my project via powershell commands
dotnet publish --configuration Release --framework netcoreapp2.2
Try it, I hope it will help...
I know this has been resolved for you. But in my own case.
IDE: Visual Studio 2017 Enterprise
Publish Profile: Folder
Follow this step:
Change the build option to the environment you want to publish for
(Test, Staging, Release or Production) and clean the solution.
Open your project folder and delete the bin and obj folders.
Restart Visual Studio
After restarting VS, delete the publish profile and re-create the profile
This should fix it as it did for me. After which I was able to publish comfortably.
I hope this helps.
My issue was resolved when I
checked "Use this connection string at runtime"
unchecked the "Default connection string"
If you are publishing to a local file System. Check whether the folder has required read/write permission for Visual Studio to copy the published files.
I have a database project in Visual Studio 2012. I am trying to create an MSBuild project to publish the database on the build server. In my solution, I have a Publish Profile that I would like to use on the build server.
I have the following target setup:
<Target Name="BuildDatabases">
<MSBuild Projects="$(DBProjectPath)" Targets="Build;Deploy" Properties="DeployOnBuild=true;SqlPublishProfilePath=BuildServer.publish">
</MSBuild>
</Target>
I've tried a combination of PublishProfile and SqlPublishProfilePath to no avail. I always receive:
Deploy Error: The connection string is not valid
I can use the Publish Profile inside VS with no connection issues.
Figured it out:
<Target Name="BuildDatabases">
<MSBuild Projects="$(DBProjectPath)" Targets="Build;Publish" Properties="DeployOnBuild=true;SqlPublishProfilePath=BuildServer.publish.xml">
</MSBuild>
</Target>
I had to use "Build;Publish" for target, I was using "Build;Deploy"
I am trying to get TeamCity to run XUnit tests as part of the build process. So I created a separate file - MyProject.msbuild - living in the same folder as the .sln file, which looks like this:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\..\bin\xunit.net\xunit.runner.msbuild.dll" TaskName="Xunit.Runner.MSBuild.xunit"
/>
<Target Name="Build">
<MSBuild Projects="MyProject.sln" Targets="Build" Properties="Configuration=Release">
<xunit Assembly="MyProject.Utility.Tests\bin\Release\MyProject.Utility.Tests.dll" />
</MSBuild>
</Target>
</Project>
However, no matter what I do, VS2010 hates me having the element inside the element. If I run MSBuild on the file, it tells me a little bit more:
P:\MyProject\src>c:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe MyProject.msbuild /tv:4.0 /v:d
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.225]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 08.11.2011 21:08:46.
Project "P:\MyProject\src\MyProject.msbuild" on node 1 (default targets).
Building with tools version "4.0".
P:\MyProject\src\MyProject.msbuild(8,9): error MSB4067: The element <xunit> beneath element <MSBuild> is unrecognized.
Done Building Project "P:\MyProject\src\MyProject.msbuild" (default targets) -- FAILED.
Build FAILED.
"P:\MyProject\src\MyProject.msbuild" (default target) (1) ->
P:\MyProject\src\MyProject.msbuild(8,9): error MSB4067: The element <xunit> beneath element <MSBuild> is unrecognized.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.01
So my current guess is that it doesn't successfully load the xunit.runner.msbuild.dll somehow - or I have done something else strange.
However, I would think that if it couldn't load xunit.runner.msbuild.dll, it would tell me about it. I made sure the file is not blocked (by unpacking the xunit distribution with 7zip).
Any ideas what I can do to get MSBuild to swallow my build file and run the tests?
You don't want to nest the calls, try this:
<Target Name="Build">
<MSBuild Projects="MyProject.sln" Targets="Build" Properties="Configuration=Release">
</MSBuild>
<xunit Assembly="MyProject.Utility.Tests\bin\Release\MyProject.Utility.Tests.dll" />
</Target>
The items within a target are executed in sequence.
Scripts.xml:
<UsingTask
TaskName="CompressorTask"
AssemblyFile="Yahoo.Yui.Compressor.dll" />
<PropertyGroup>
<JavaScriptOutputFile Condition=" '$(JavaScriptOutputFile)'=='' ">..\..\site.com\javascript\offerta.min.js</JavaScriptOutputFile>
</PropertyGroup>
<Target Name="ScriptTask">
<ItemGroup>
<JavaScriptFiles Include="..\..\site.com\javascript\offerta.js"/>
</ItemGroup>
<CompressorTask
JavaScriptFiles="#(JavaScriptFiles)"
ObfuscateJavaScript="True"
PreserveAllSemicolons="True"
DisableOptimizations="False"
EncodingType="utf-8"
DeleteJavaScriptFiles="false"
LineBreakPosition="-1"
JavaScriptOutputFile="$(JavaScriptOutputFile)"
LoggingType="HardcoreBringItOn"
ThreadCulture="en-us"
IsEvalIgnored="false" />
</Target>
I run it using a bat file:
C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe Scripts.xml
pause
I'm getting:
"F:\Checkouts\Offerta\trunk\build\site.com\Scripts.xml" (default target) (1)
->
(ScriptTask target) ->
F:\Checkouts\Offerta\trunk\build\site.com\Scripts.xml(16,7): error MSB4036:
The "CompressorTask" 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 inte
rface. 3.) The task is correctly declared with in the project file,
or in the *.tasks files located in the "C:\Windows\Microsoft.NET\Framework\v2.
0.50727" directory.
What am I doing wrong? I'm using Yahoo.Yui.Compressor v1.6.0.0.zip (for .NET 3.5). Why is msbuild reporting "C:\Windows\Microsoft.NET\Framework\v2.0.50727" when I explicity run C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe?
Use Yahoo.Yui.Compressor.MsBuildTask.dll version 1.6.0.1
Unfortunaltelly this version is available only via Nuget Library
Details at: http://yuicompressor.codeplex.com/discussions/272802