27

I am trying to setup a website and webjob, but get an error everytime I try to publish the webjob independently of the website (i.e. Selecting Publish as Azure WebJob from the context menu)

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets(4270,5): Error : The 'MyWebJob.Models.MyDataEntities-Web.config Connection String' argument cannot be null or empty.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets(4270,5): Error : The 'MyWebJob.Models.MoreDataEntities-Web.config Connection String' argument cannot be null or empty.

There are two options for deploying a WebJob

When I link my webjob to a website project, it deploys with the website without error. However, when I try to deploy it independently I get the above error in my console and Error List, but the webjob is still deployed.

How can I deploy my webjob independently and get rid of this persistent "error"?

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
Enrico
  • 10,377
  • 8
  • 44
  • 55

3 Answers3

48

I found that providing a value for

 <Destination Path="" /> 

in your publish profile pubxml file got rid of the issue. This can usually be found in \Properties\PublishProfiles. You probably have something like:

<PublishDatabaseSettings>
  <Objects xmlns="">
    <ObjectGroup Name="Context" Order="1" Enabled="False">
      <Destination Path="" />
      <Object Type="DbCodeFirst">
        <Source Path="DBMigration" DbContext="Context, DAO" MigrationConfiguration="Context.Migrations.Configuration, DAO" Origin="Convention" />
      </Object>
    </ObjectGroup>
  </Objects>
</PublishDatabaseSettings>

Changing it to the following fixed it for me:

<PublishDatabaseSettings>
  <Objects xmlns="">
    <ObjectGroup Name="Context" Order="1" Enabled="False">
      <Destination Path="{deployment connection string}" />
      <Object Type="DbCodeFirst">
        <Source Path="DBMigration" DbContext="Context, DAO" MigrationConfiguration="Context.Migrations.Configuration, DAO" Origin="Convention" />
      </Object>
    </ObjectGroup>
  </Objects>
</PublishDatabaseSettings>

Hope that helps.

Willisterman
  • 583
  • 3
  • 5
  • This works for me sometimes. I have a project with multiple profiles. It worked for one but not the other. – jrummell Jul 06 '15 at 15:28
  • 3
    Ok, it seems to work if you restart Visual Studio after changing the pubxml file. – jrummell Jul 06 '15 at 15:33
  • I can confirm that this worked for me also, but do we have any idea what caused the problem? – Niklas May 19 '16 at 07:36
  • 1
    what exactly should i write into {deployment connection string}. currently my visual studio instance crashes while trying to deploy the webjob... – skorzinetzki Nov 03 '16 at 09:17
  • @jrummell is correct in reloading project after making changes works. You can also "unload" the project and load it again which is quicker than closing and restarting VS. – Skiltz Jan 05 '17 at 08:30
  • 3
    @skorzinetzki I literally put the letter `s` there and it started working. What a shit process. – SB2055 Jun 17 '17 at 14:27
  • The given answer above doesn't tell us what to enter here, unless we indeed want to stinking duplicate our full connection string in every webjobs stupid profile. So I want to reiterate @SB2055 's point above, I entered simply the letter 'z' like follows: `` and that seems to work. And yes, this is ridiculous. I wouldn't complain, if it was not for the fact this situation has existed for so long; outside of webjobs, every web publish tries to force you to fill out your connection strings and I have to manually remove them, I do connection strings dynamically. – Nicholas Petersen Aug 30 '18 at 19:30
3

I found that deleting the obj directory within the WebJob project will clear the staging area in which the WebJob package to be published is being built. Publish was then successful.

Craigology
  • 161
  • 3
1

Reason of the problem
Change the name of the connection string in the Web.Config or/and adding a new connection string to the Web.Config.

Solution

  1. Select the website project, right click on it, and click publish.
    enter image description here

  1. Press the settings link and from the pop-up window select the 'Settings' Tab

  2. Uncheck the use this connection string at runtime from all your connection strings.

enter image description here

  1. Click Save button to close the the window. (No need to Restart Visual Studio)
  2. Try to publish the website again, and it should publish without problem.

NOTE
I am using VS 2017

Just for Note
After I did the previous steps, I noticed that the .pubxml file changed automatically. here is the difference which has been made (automatically without any interference from me)

So I think this is better way because it is easier for developer and also it let the visual studio to solve its problems himself, without forcing it for specific thing.

enter image description here

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131