1

my idea to replace named tag UrlPublish to my needed path on .csproj file , i need to do it 10 times(path1, path2, path3...) to create 10 different msbuild deployment manifests. i have a following code:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0" DefaultTargets="Build">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
  <!--This section defines project-level properties.AssemblyNameName of the output assembly.ConfigurationSpecifies a default value for debug.OutputTypeMust be "Library" for VSTO.PlatformSpecifies what CPU the output of this project can run on.NoStandardLibrariesSet to "false" for VSTO.RootNamespaceIn C#, this specifies the namespace given to new files. In VB, all objects arewrapped in this namespace at runtime.-->
  <PropertyGroup>
    <ProjectTypeGuids>{asdasdd-18E2-41B9-852F-Fsdsdsd0CAA33};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{xxxxxxx-6155-4C9E-91A0-xxxxxx552}</ProjectGuid>
    <OutputType>Library</OutputType>
    <NoStandardLibraries>false</NoStandardLibraries>
    <RootNamespace>Com.project.Distribution.Mvp</RootNamespace>
    <AssemblyName>Com.project.Distribution.Mvp</AssemblyName>
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <DefineConstants>VSTO40</DefineConstants>
    <IsWebBootstrapper>False</IsWebBootstrapper>
    <FileUpgradeFlags/>
    <UpgradeBackupLocation/>
    <OldToolsVersion>15.0</OldToolsVersion>
    <VSTO_TrustAssembliesLocation>true</VSTO_TrustAssembliesLocation>
    <BootstrapperEnabled>true</BootstrapperEnabled>
    <PublishUrl>path</PublishUrl>
    <InstallUrl/>
    <TargetCulture>en</TargetCulture>
    <ApplicationVersion>1.0.1.8</ApplicationVersion>
    <AutoIncrementApplicationRevision>true</AutoIncrementApplicationRevision>
    <UpdateEnabled>true</UpdateEnabled>
    <UpdateInterval>2</UpdateInterval>
    <UpdateIntervalUnits>hours</UpdateIntervalUnits>
    <ProductName>Com.project.Distribution.Mvp</ProductName>
    <PublisherName/>
    <SupportUrl/>
    <FriendlyName>Com.project.Distribution.Mvp</FriendlyName>
    <OfficeApplicationDescription/>
    <LoadBehavior>3</LoadBehavior>
  </PropertyGroup>
  <ItemGroup>
    <BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
      <Visible>False</Visible>
      <ProductName>Microsoft .NET Framework 4.5.2 %28x86 and x64%29</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Office.PIARedist.2007">
      <Visible>False</Visible>
      <ProductName>Microsoft Office 2007 Primary Interop Assemblies</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.VSTORuntime.4.0">
      <Visible>False</Visible>
      <ProductName>Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 and x64%29</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
      <Visible>False</Visible>
      <ProductName>Windows Installer 3.1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
  </ItemGroup>
  <PropertyGroup>

I try to using Python and xml parser. But if i try to find a PublishUrl tag i don't get changes ... my python code is :

   import xml.etree.ElementTree as ET
    tree = ET.parse('file.csproj')
    root = tree.getroot()
    elem = tree.findall(".//PublishUrl")
    print(elem)

How can i parse .csproj file? its not xml and i don't understand how can i replace tag value.

3
  • 1
    You could also call msbuild 10 times and pass a different `/p:PublishUrl=C:\out\path123` parameter on the command line to overwrite what's in the file Commented Nov 26, 2017 at 17:14
  • @MartinUllrich look , well , i have a .txt file with 10(1 path on 1 line) paths yes? how can i add this lines on PublishUrl each time then i do msbuild??? maybe i can do it with bash or something same. Commented Nov 26, 2017 at 17:16
  • 1
    AFAIK, .csproj file should be a XML file: msdn.microsoft.com/en-us/library/5dy88c2e.aspx. And Python supports a variety of modules to work with various forms of structured data markup includes several interfaces for working with the XML. stackoverflow.com/questions/6959824/… Commented Nov 27, 2017 at 7:58

1 Answer 1

1

The problem is with xmlns. Try:

    import xml.etree.ElementTree as ET
    tree = ET.parse('file.csproj')
    root = tree.getroot()
    elem = tree.findall(".//{http://schemas.microsoft.com/developer/msbuild/2003}PublishUrl")
    print(elem)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.