简体   繁体   中英

Why doesn't Exec Command work in a .csproj for netstandard2.0?

I'm busy moving my code from .Net Framework libraries to .netstandard2.0 libraries. So far it's going pretty well, but now i'm stuck with the in the .csproj file.

The existing project file has this defined

  <Target Name="Rebuild">
    <Exec Command="echo Now Rebuilding the package" />
  </Target>

the actual command executes an exe that generates a bunch of xml classes based on an xsd.

I cannot get this to work in a .netstandard2.0 project?

I've searched everywhere but i cannot find a reason for this not working...

I suspect that in your specific instance, the Rebuild target will be overwritten by the sdk targets that are implicitly imported after your code. If you want to overwrite SDK-provided tasks, you need to change to explicit SDK imports (instead of <Project Sdk="..."> ):

<Project>
  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
  <!-- other project content -->
  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
  <Target Name="Build">
    <!-- overwrite Build target here -->
  </Target>
  <Target Name="Rebuild">
    <!-- overwrite Rebuild target here -->
  </Target>
</Project>

The Exec target is supported though the echo command may or may not work depending on the platform you are running it on (since echo may be just a built-in command of the shell but no executable that can be run).

Make sure that:

  • The command starts with the path to an executable that is found on the PATH or is specified absolute or relative to the csproj file being built.
  • The target is actually executed. Eg some programs could use /t:Clean;Build instead of /t:Rebuild .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM