9

I want to publish my web site after building.Is there any way to run dotnet publish command in post build event in asp,net core? This is my project.json file:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Model": "1.0.0-*",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0"

  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [
      //"bower install"
    ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ],
    "postbuild": "[call  $(ProjectDir)Publish.bat]"

  }
}
  • have you tried running `dotnet publish` as a `postcompile` script? – Pawel Sep 01 '16 at 05:10
  • @Pawel yes it doesn't work –  Sep 01 '16 at 05:14
  • I don't know what it means exactly... - is there an error or what? (as a side note - I am not quite sure why you would even want to publish on build...) – Pawel Sep 01 '16 at 05:16
  • @Pawel I test it:dotnet publish --framework netcoreapp1.0 --output "c:\temp\Api" --configuration Release but not working.i also try to running bat file but not work again. –  Sep 01 '16 at 05:17
  • again "not working" is very vague. Can it be that you build Debug but try to publish Release or you build net461 and publish netcoreapp1.0? – Pawel Sep 01 '16 at 05:19

1 Answers1

18

Add the --no-build parameter to dotnet publish in your post-build event. By default, dotnet publish will run a build, which will trigger post-build events, which will then try to publish again, which will cause an infinite loop that appears to make the build hang.

Allen Aston
  • 521
  • 5
  • 9