visual studio - Programmatically building c# webapplications projects gives errors on opening project -


i want build freshly new added standard asp (mvc) webapplication programmatically in visual studio 2017. therefore use console application uses microsoft.build.evaluation.project.build() open , compile project. console application builds outlined below. project needs build standard asp mvc .net application generated wizard in visual studio. in visual studio version 2017 compiles fine. if want compile using application , @ opening of project, comes error :

microsoft.build.exceptions.invalidprojectfileexception occurred hresult=0x80131500 message=the imported project "c:\program files (x86)\msbuild\microsoft\visualstudio\v15.0\webapplications\microsoft.webapplication.targets" not found. confirm path in declaration correct, , file exists on disk.

now, if open csproj file of webapplication in notepad tells wants find it's imported projects in:

import project="$(vstoolspath)\webapplications\microsoft.webapplication.targets" condition="'$(vstoolspath)' != ''"

according tot error seems me toolspath "c:\program files (x86)\msbuild\microsoft\visualstudio\v15.0" webapplications\microsoft.webapplication.targets located in "c:\program files (x86)\msbuild\microsoft\visualstudio\v14.0"

a workaround copy webapplications folder v14.0 v15.0. compiles happily. questions : why standard generated project pointing directory not exsist? why can visual studio cope wrong path? there better solution copy webapplications folder ?

here code opens , compiles web project:

using system; using microsoft.build.logging;   namespace compilerapp { class program {     static void main(string[] args)     {         //string projectfile = @"c:\temp\compilerapp\mycsharp7\mycsharp7.csproj";          string projectfile = @"c:\temp\compilerapp\webapplication1\webapplication1.csproj";         unloadanyproject();         microsoft.build.evaluation.project p = new microsoft.build.evaluation.project(projectfile);         filelogger loggerfile2 = new filelogger();         loggerfile2.parameters = @"logfile=c:\temp\compilerapp\myapp.msbuild.log";         bool buildresult = p.build(loggerfile2);         if (buildresult)         {             console.writeline("project compiled");         }         else         {             console.writeline("project not compiled, check {0}", @"c:\temp\myapp.msbuild.log");          }         p.save();         unloadanyproject();       }      private static void unloadanyproject()     {         microsoft.build.evaluation.projectcollection projcoll = microsoft.build.evaluation.projectcollection.globalprojectcollection;          foreach (microsoft.build.evaluation.project pr in projcoll.loadedprojects)         {             microsoft.build.evaluation.projectcollection mypcollection = pr.projectcollection;             mypcollection.unloadproject(pr);         }     } } } 

why standard generated project pointing directory not exsist? why can visual studio cope wrong path? there better solution copy webapplications folder ?

i have reproduced problem code. issue not occurred on visual studio 2015 same scripts , visual studio compile after test.

after more investigation, have noticed project class of "microsoft.build.evaluation.project" did not read correct path of visual studio 2017, toolpath on vs2017 should c:\program files (x86)\microsoft visual studio\2017\professional\msbuild\microsoft\visualstudio\v15.‌​0, not check source code of project class ilspy.

so have reported issue visual studio developer community (thanks contribution), can follow comments , check feedback of issue. follow issue, send latest status of issue.

https://developercommunity.visualstudio.com/content/problem/45156/the-project-class-of-microsoftbuildevaluationproje.html

hope can you.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -