C # Solution generation tools (2)

Source: Internet
Author: User

Environment VS2017 Community Edition W10

Project class: Under the Microsoft.Build.Evaluation namespace, you can use the project class to parse the. csproj file for your project

Instantiate the object, which is the path to the project's. csproj file

var proj = new Project ("D:/xxx/xxx.csproj");

Calling this method updates the. csproj file.

Proj. Save ()

If you specify a path, it is saved to the new path, and you can use a. csproj template to create a new. csproj file for various projects.

Proj. Save (new Path)//Saves the current. csproj file to a new path, the source has no changes to the file.

Gets the value of the property based on the property name. Use this method to get information about the project, such as the project name, project path

Proj. GetPropertyValue ("ProjectName")//Get project name

By printing the name value pairs of all properties, you can know which properties are available.

Proj. The properties//display has 328 properties, almost all of which have to be known.

Problems encountered during use:

When instantiating an ASP. csproj file, the instantiation fails, and the exception shows that the Microsoft.WebApplication.targets is not found WEBAPI.

After looking at the. csproj file, it is considered that there are three nodes with which the phase is closed:

<project toolsversion= "12.0"//different versions of VS are different, and the project type is not the same. vs2017 DLL project value display is 15

The following two nodes indicate the Microsoft.WebApplication.targets reference path, which seems to be the problem because this is not found in this path.

<import project= "$ (vstoolspath) \webapplications\microsoft.webapplication.targets" Condition= "' $ (VSToolsPath) ' ! = ' "/>
<import project= "$ (MSBuildExtensionsPath32) \microsoft\visualstudio\v10.0\webapplications\ Microsoft.WebApplication.targets "condition=" false "/>

Since the node attribute is not analyzed, it is not necessary to modify the value of the node attribute to solve the problem. By finding the Microsoft.WebApplication.targets file in this machine, we find two directories.

vs Compiler Tool Catalog V15

C:\Program Files (x86) \msbuild\microsoft\visualstudio\v14.0

Vs2017community Compiling Tools Catalog 15

C:\Program Files (x86) \microsoft Visual studio\2017\community\msbuild\microsoft\visualstudio\v15.0

The 2nd directory is the directory where the VS2017 is installed, and the 1th directory is unclear. Maybe it has something to do with installing vs. the exception information appears to be missing Microsoft.WebApplication.targets The error path is not found in the 1th directory. It appears that the compilation tool defaults to

Find the 1th path under the V15 version of this file, and then find that it was not found. because it wasn't.

The final workaround is to copy the webapplications folder under the 2nd directory to the 1th directory, but the corresponding V15 version directory. That is:

  C:\Program Files (x86) \msbuild\microsoft\visualstudio\v15.0 will then find no exception. Instantiation succeeded.

C # Solution generation tools (2)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.