locked
Web Site Publish Question - .sln vs .csproj... RRS feed

  • Question

  • User634540520 posted

    Hi all,

    I have a quick series of questions regarding publishing a website.

    When we deploy using the .sln file, it seems the .sln and other development files are pushed to the desired location.  Is there a way to filter that stuff out and only deploy what will be needed in the install/on end user's machine.

    We will be adding this via MSBuild as well in a script for our CI project and I'm wondering if there is a parameter that can be passed to it to filter that 'stuff'.

    We do publish another app that uses a .csproj file and we don't have to do any cleanup of dev files there.  Everything looks good from both Visual Studio and our CI process.

    Is that the difference?  If its a project and not a solution the publish is cleaner?

    The developer in charge of this particular solution indicated that the publish looked good if the .sln file was removed.  The problem with that is I have nothing to call or build/publish via MSBuild in our script.

    Any clarity you can provide would be greatly appreciated!!

    Thanks in advance.

    Tuesday, January 19, 2016 12:19 AM

Answers

  • User-166373564 posted

    Hi, 

    In a web application project, source code is compiled into an assembly (a .dll file), and that is what has to be on the web server.

    According to your description above, there are the steps to follow in order to exclude specific file(s) and/or folder(s) from packaging and/or publishing:

    1. Open the web application project file (.csproj or .vbproj) in an editor or from within Visual Studio itself
    2. Add an <ExcludeFilesFromDeployment> and/or <ExcludeFoldersFromDeployment> element in the desired <PropertyGroup> element.
    3. Save the project file

    4. Reload the project

    5. Build your Deployment Package or Publish Web …

    More information: Excluding Files and Folders via the Web Application’s Project File

    In addition, if you want to use MSBuild to publish your application, you can consider getting help from MSBuild forum.

    Regards,

    Angie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 25, 2016 8:41 AM

All replies

  • User634540520 posted

    OK, so I think I may have this problem solved.  I was able to add the files I want to exclude to the .pubxml via <ExcludeFilesFromDeployment>.

    Now, however there is another problem.  When I build the site in Visual Studio (2015), not problems and it results in success.

    If I use MSBuild it errors copying two files...

    Build FAILED.
    
    "C:\src\MyAppNet\MyAppWeb\MyCompany.WebViewer\MyCompany.WebViewer.sln" (default target) (1) ->
    "C:\src\MyAppNet\MyAppWeb\MyCompany.WebViewer\MyCompany_WebViewer.metaproj" (default target) (2) ->
    (Build target) -> 
      C:\src\MyAppNet\MyAppWeb\MyCompany.WebViewer\MyCompany_WebViewer.metaproj : error MSB3021: Unable to copy file "C:\src\MyAppNet\MyAppWeb\MyCompany.WebViewer\packages\Newto
    nsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll" to "..\MyCompany.WebViewer\\Bin\Newtonsoft.Json.dll". Access to the path '..\MyCompany.WebViewer\\Bin\Newtonsoft.Json.dll' i
    s denied.
      C:\src\MyAppNet\MyAppWeb\MyCompany.WebViewer\MyCompany_WebViewer.metaproj : error MSB3021: Unable to copy file "C:\src\MyAppNet\MyAppWeb\MyCompany.WebViewer\packages\Newto
    nsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.xml" to "..\MyCompany.WebViewer\\Bin\Newtonsoft.Json.xml". Access to the path '..\MyCompany.WebViewer\\Bin\Newtonsoft.Json.xml' i
    s denied.
    

    These Newtonsoft .dll's are generated as packages during our Continuous Integration, TFS Prebuild script and they do seem to be in the correct place.

    Where are these copies configured in our project (website)?  It seems that there is something funky with the destination paths.  All other files copied during the build are displayed as Bin\<some subfolder>\file.dll and not ..\MyCompany.WebViewer\\.

    Not only that, it begs the question, why does it work with Devenv.exe and not MSBuild.exe?

    I hope someone out there can help because this is driving me absolutely nuts as I've tried to incorporate this into our build process so we can publish it via MSBuild.

    Here are the MSBuild options we are using...

    "/p:DeployOnBuild=true /p:PublishProfile='Deploy FS2 for nAWC' /p:VisualStudioVersion=14.0 /p:AspnetMergePath='C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools'"

    Please help!!  Cry

    Tuesday, January 19, 2016 7:36 PM
  • User634540520 posted

    Maybe the question should be...  How should I properly build/publish a website via MSBuild on a Team Foundation Build Server?

    What I'm currently trying to do is carry this out via MSBuild command line from a power shell script.  In our Pre-Build script I install some needed packages because it seems that MSBuild doesn't auto refresh the packages.  So, the prebuild script runs and the packages are installed where they are needed.

    I've tried various things from this point, as explained above, but I cannot get the site to build/publish.

    I've been surfing the web and see that there are xml files referenced as MSBuild scripts that appeared to be part of the particular project.  Is this how it is done?  Is there some configuration file I can create which the TFS Build (msbuild) notices/references to build the site?

    As stated, any help would be Awesome!!

    Thursday, January 21, 2016 1:32 AM
  • User634540520 posted

    OK, after really examining the errors I was seeing I discovered that the Dev responsible for this project checked his package files into TFS in the \bin directory.  After removing those from TFS, it appears I'm able to build the site - sort of...

    I build it once successfully in Visual Studio to ensure the removal of the files worked.  Then I try to Publish the site and I get this...

    It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.

    I searched and some older posts say there are too many web.config files mucking things up.

    How can I jump this hurdle/fix this problem?

    Friday, January 22, 2016 1:35 AM
  • User-166373564 posted

    Hi, 

    In a web application project, source code is compiled into an assembly (a .dll file), and that is what has to be on the web server.

    According to your description above, there are the steps to follow in order to exclude specific file(s) and/or folder(s) from packaging and/or publishing:

    1. Open the web application project file (.csproj or .vbproj) in an editor or from within Visual Studio itself
    2. Add an <ExcludeFilesFromDeployment> and/or <ExcludeFoldersFromDeployment> element in the desired <PropertyGroup> element.
    3. Save the project file

    4. Reload the project

    5. Build your Deployment Package or Publish Web …

    More information: Excluding Files and Folders via the Web Application’s Project File

    In addition, if you want to use MSBuild to publish your application, you can consider getting help from MSBuild forum.

    Regards,

    Angie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 25, 2016 8:41 AM