none
Publishing to Azure From Visual Studio Command line fails RRS feed

  • Question

  • Hi,

    I am having issue publishing a Web App to Azure, using MSBuild command.

    Seems like issue is happening because of using “using System.Security.Claims;”.

    I have a sample web application, Visual Studio 2017, c#, Web Site project.

    On my web page, I simply added “using System.Security.Claims;”, no any other code.

    I have saved my “SampleWebSite1-WebDeploy.pubxml” file which is as below.

    ============================================================================================================================

    <?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>MSDeploy</WebPublishMethod>
    
        <ADUsesOwinOrOpenIdConnect>False</ADUsesOwinOrOpenIdConnect>
    
        <PublishProvider>AzureWebSite</PublishProvider>
    
        <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    
        <LastUsedPlatform>Any CPU</LastUsedPlatform>
    
        <SiteUrlToLaunchAfterPublish>XXX</SiteUrlToLaunchAfterPublish>
    
        <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    
        <ExcludeApp_Data>True</ExcludeApp_Data>
    
        <MSDeployServiceURL>XXX</MSDeployServiceURL>
    
        <DeployIisAppPath>SampleWebApplication1</DeployIisAppPath>
    
        <RemoteSitePhysicalPath />
    
        <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
    
        <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    
        <EnableMSDeployBackup>True</EnableMSDeployBackup>
    
        <UserName>$SampleWebApplication1</UserName>
    
        <Password>XXX</Password>
    
        <_SavePWD>True</_SavePWD>
    
        <_DestinationType>AzureWebSite</_DestinationType>
    
        <EnableUpdateable>False</EnableUpdateable>
    
        <DebugSymbols>False</DebugSymbols>
    
        <WDPMergeOption>DonotMerge</WDPMergeOption>
    
        <PrecompileBeforePublish>True</PrecompileBeforePublish>
    
        <ExcludeFilesFromDeployment>web.config</ExcludeFilesFromDeployment>
    
      </PropertyGroup>
    
    </Project>


    ============================================================================================================================

    I am running below command to publish my web site to Azure, using this profile.

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin>msbuild C:\XXX\WebApplication1\WebSite1 /p:DeployOnBuild=True  /p:PublishProfile=C:\XXX\WebApplication1\WebSite1\App_Data\PublishProfiles\SampleWebSite1-WebDeploy.pubxml

    But if fails with below error.

    ============================================================================================================================

    AspNetPreCompile:

      C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /WebSite1 -p C:\Users\XXX\AppData\Local\Temp\WebSitePublish\WebSite1-934461955\obj\Debug\AspnetCompileMerge\Source -c C:\Users\XXX\AppData\Local\Temp\WebSite

      Publish\WebSite1-934461955\obj\Debug\AspnetCompileMerge\TempBuildDir

    c:\Users\XXX\AppData\Local\Temp\WebSitePublish\WebSite1-934461955\obj\Debug\AspnetCompileMerge\Source\Default.aspx.cs(7): error CS0234: The type or namespace name 'Claims' does not exist in the namespace 'System.Security' (are you m

    issing an assembly reference?) [C:\XXX\WebApplication1\WebSite1\website.publishproj]

    Done Building Project "C:\XXX\WebApplication1\WebSite1\website.publishproj" (default targets) -- FAILED.

    Build FAILED.

    "C:\XXX\WebApplication1\WebSite1\website.publishproj" (default target) (1) ->

    (AspNetPreCompile target) ->

      c:\Users\XXX\AppData\Local\Temp\WebSitePublish\WebSite1-934461955\obj\Debug\AspnetCompileMerge\Source\Default.aspx.cs(7): error CS0234: The type or namespace name 'Claims' does not exist in the namespace 'System.Security' (are you

     missing an assembly reference?) [C:\XXX\WebApplication1\WebSite1\website.publishproj]

        0 Warning(s)

        1 Error(s)

    ============================================================================================================================

    While publishing, I need to keep these two options in my profile, to precompile files so that it does not publish actual code files (.cs) and it excludes web.config file from publishing.

        <PrecompileBeforePublish>True</PrecompileBeforePublish>

        <ExcludeFilesFromDeployment>web.config</ExcludeFilesFromDeployment>

    If I remove any of these option, it correctly publishes site on Azure.

    But the issue is happening because of having both options together.

    If I keep  <PrecompileBeforePublish>True</PrecompileBeforePublish>, it always fails with the error “error CS0234: The type or namespace name 'Claims' does not exist in the namespace 'System.Security' (are you

     missing an assembly reference?) [C:\XXX\WebApplication1\WebSite1\website.publishproj]

    I tried various options but could not make this working.

    So can someone help me to publish this sample web application, to Azure, using given command, with both the options  <PrecompileBeforePublish>True</PrecompileBeforePublish> and <ExcludeFilesFromDeployment>web.config</ExcludeFilesFromDeployment>.

    Monday, July 29, 2019 8:41 PM

All replies

  • Hi Sr.Ddeveloper-NY,

    Welcome to the MSDN forum.

    It seems that you failed to build your project. You can try these steps:

       1. please check whether you add the reference "System.Web". If not, please add it.

       2. try to install the Package "System.Security.Claims"

       3. add this into proj file

    <Reference Include="System.Web.dll">
    
    <HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1\System.Web.dll</HintPath>
    </Reference>

    >>Note: The  HintPath is the path to your local system.web.dll. It usually locates in Reference Assemblies folder and make sure the correct location in your machine.

    About error CS0234, you can refer this:

    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0234

    If it does not work, please feel free to let us know and share some screenshots of proj file if necessary.

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com



    Tuesday, July 30, 2019 6:55 AM
  • Thanks for reply Perry. 

    actually as I mentioned, this is a ASP.Net Web Site, not web project so this does not have .csproj file. 

    Second, this issue somehow seems specific to using using System.Security.Claims;" namespace. 

    Lets say if I comment that line and publish, everything works fine. 

    Here are the different results.

    1. if I have "using System.Security.Claims;" line in code, project builds fine but does not publish using this publish profile. 

    2. if I have "using System.Security.Claims;" line in code, and I remove any one of these two from profile, it publishes. 

    <PrecompileBeforePublish>True</PrecompileBeforePublish>

        <ExcludeFilesFromDeployment>web.config</ExcludeFilesFromDeployment>

    3. If I comment out OR Remove line  "using System.Security.Claims;", project publishes correctly even with having both the options in publish file. 

    <PrecompileBeforePublish>True</PrecompileBeforePublish>

        <ExcludeFilesFromDeployment>web.config</ExcludeFilesFromDeployment>

    I have already added reference to the web site for System.IdentityModel.

    And project always builds and runs successfully. There is issue only while publishing using this publish profile. 

    Even from visual studio, I am not able to preview this profile. Preview failed with same error.

    "The type or namespace name 'Claims' does not exist in the namespace 'System.Security' (are you missing an assembly reference?)"

    And real issue again is, using this publish profile when I have these two options in profile, it fails somehow to identify system.security.model namespace. not sure why. 

    <PrecompileBeforePublish>True</PrecompileBeforePublish>

        <ExcludeFilesFromDeployment>web.config</ExcludeFilesFromDeployment>

    But I need to have both in publish profile because I need to precompile and need to remove web.config.  

    Tuesday, July 30, 2019 2:31 PM
  • Hi Sr.Developer-NY,

    Thanks for your feedback.

    After a deep discussion with my team members, we got an answer that we do not recommend you use the PrecompileBeforePublish parameter. Precompilation should not be a deployment step. Instead, it should happen after build but before packaging the web application. It always reports an error when you perform this step to deploy website on command line.

    >>You should follow your second step and delete the PrecompileBeforePublish  order.

    l hope it could help you.

    Best Regards,

    Perry



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, July 31, 2019 9:47 AM
  • Thanks Perry, 

    Yes, I can remove PrecompileBeforePublish  from my profile but then it will publish entire code as is. It will include all *.cs files also when it deploys. 

    So the option for me is, do not include PrecompileBeforePublish , and exclude all files *.cs, web.config and other specific files using ExcludeFilesFromDeployment.

    That will work but somehow I am still surprised that when I use PrecompileBeforePublish, why it fails to compile only for specific namespace "using System.Security.Claims;". and If I comment this, I am able to use "PrecompileBeforePublish". This is little strange and I could not figure out. 

    However, if no other solution, as I said I will not use "PrecompileBeforePublish" and will exclude specific files and extensions using "ExcludeFilesFromDeployment".

    Thanks again. 

    Wednesday, July 31, 2019 3:13 PM
  • Actually as this is a web site, not web project, looks like will need to set option "PrecompileBeforePublish" to compile and to exclude all *.cs and source code files from deployment.

    Or else it deploys entire code as is, .aspx, .cs all files as is. 

    So will have to use "PrecompileBeforePublish" option. 

    So I am still trying to find out solution why it fails to compile when I have "PrecompileBeforePublish" and "<ExcludeFilesFromDeployment>web.config</ExcludeFilesFromDeployment>" options together.

    Again, it fails to compile and gives error at "using System.Security.Claims;"" when I have both of these options in .pubXML file.

    Also one more strange thing is, it fails only when there is web.config inside "<ExcludeFilesFromDeployment>web.config</ExcludeFilesFromDeployment>", it works for any other file, for example if I keep it as "<ExcludeFilesFromDeployment>default.aspx</ExcludeFilesFromDeployment>" it correctly compiles and publishes to Azure. 

    Not able to understand why it gives error "The type or namespace name 'Claims' does not exist in the namespace 'System.Security' (are you missing an assembly reference?)" when I have "<ExcludeFilesFromDeployment>Web.config</ExcludeFilesFromDeployment>" and "<PrecompileBeforePublish>True</PrecompileBeforePublish>" in my pubXML File. 

    Wednesday, July 31, 2019 4:15 PM
  • Hi Sr.Developer-NY,

    Since the problem is more complex, you can refer to this document:

    https://docs.microsoft.com/en-us/aspnet/web-forms/overview/older-versions-getting-started/deploying-web-site-projects/precompiling-your-website-cs

    Best Regards,

    Perry



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, August 1, 2019 10:29 AM
  • Hi Sr.Developer-NY,

    As far as I know, the web.config file contains the some reference relationships during the code files and dlls files, and pre-compiling needs to find all reference relationships and copy all code into production environment.

    <ExcludeFilesFromDeployment> will exclude specified files before deploy, so that the file could not be pre-compiled.

    So we recommend you could remove <ExcludeFilesFromDeployment>.

    Of course, you could also set the output path, then pre-compile website using msbuild locally, then publish related files to server.

    command line:

    msbuild WebSite1.sln /p:PrecompileBeforePublish=true

    output path(right-click projects -> property page):

    Hope it could help you.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, August 5, 2019 10:34 AM